[comp.sys.mac.hypercard] Protecting individual cards

BBOLT@vm.ucs.UAlberta.CA (Bob Bolt) (08/31/90)

I have been working on a stack in which I would like to be able to protect
individual cards from being deleted when certain conditions are met, such
as a field containing an entry. If the field is empty, the card can be
Cut or Deleted. If the field contains something, then the card should be
protected. I realize that I can protect the card by clicking the check
box in Card Info, but I want to set this property from a script. The only
way I can see is the following:
 
on deleteCard
   if field fieldName is not empty then
      doMenu "Copy Card"
      doMenu "Paste Card"
   end if
 
end deleteCard
 
Placing this handler in the Background script provides the protection,but
it is not exactly the cleanest way to handle the job and it has the
unfortunate side effect of changing the card id number.
 
If anyone knows of a way to handle this more efficiently, I would appreciate
hearing about it.
 
Bob Bolt
BBOLT@VM.UCS.ALBERTA.CA

chh9@quads.uchicago.edu (Conrad Halton Halling) (09/01/90)

In article <988@vm.ucs.UAlberta.CA> BBOLT@vm.ucs.UAlberta.CA writes:
>I have been working on a stack in which I would like to be able to protect
>individual cards from being deleted when certain conditions are met, such
>as a field containing an entry. If the field is empty, the card can be
>Cut or Deleted. If the field contains something, then the card should be
>protected. I realize that I can protect the card by clicking the check
>box in Card Info, but I want to set this property from a script.


The way to solve this problem is to put a doMenu handler into the background
script.  Assuming the background field has the name "myField", here is a
script for you to use:

on doMenu menuItem
  -- put this handler into the background script
  if menuItem is "Cut Card" or menuItem is "Delete Card" then
    if fld "myField" is empty then
      pass doMenu
    end if
  else pass doMenu
end doMenu

This script will not pass doMenu if fld "myField" is not empty; hence, the
cut or delete command will not take place.

When you use a doMenu handler, it is _essential_ that you put 
"else pass doMenu" in the last line of the handler.  Otherwise, no menu
command will work, and you can't do anything.  This sort of handler gives
you alot of control over what the user can or can't do.

--
Conrad Halling
chh9@midway.uchicago.edu

jdevoto@Apple.COM (Jeanne A. E. DeVoto) (09/01/90)

In article <988@vm.ucs.UAlberta.CA> BBOLT@vm.ucs.UAlberta.CA writes:
>I have been working on a stack in which I would like to be able to protect
>individual cards from being deleted when certain conditions are met, such
>as a field containing an entry. If the field is empty, the card can be
>Cut or Deleted. If the field contains something, then the card should be
>protected. I realize that I can protect the card by clicking the check
>box in Card Info, but I want to set this property from a script.

The property you're looking for is cantDelete. It is a property of cards,
backgrounds, and stacks, and corresponds to the checkbox in the Info
dialog. One way to do what you want is to place the following in the
field's script:

  on closeField
    if target is empty then
      set the cantDelete of this card to false
    else
      set the cantDelete of this card to true
    end if
  end closeField
-- 
========= jeanne a. e. devoto ========================================
 jdevoto@apple.com     |  You may not distribute this article under a
 jdevoto@well.sf.ca.us |  compilation copyright without my permission.
______________________________________________________________________
 Apple Computer and I are not authorized      |        CI$: 72411,165
 to speak for each other.                     |