How to trap deleteCard?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Timothy
Posts: 78
Joined: Tue Apr 11, 2006 7:38 pm

How to trap deleteCard?

Post by Timothy » Fri Jun 29, 2007 7:50 am

Code: Select all

on deleteCard
  if the cantDelete of this card is "true" then
    answer "You must unlock the padlock icon before you can delete this card."
  else
    pass deleteCard
  end if
end deleteCard
The button with the padlock icon sets the cantDelete of the card to true or false. (It's not quite that simple. The padlock icon gets set on openCard, but I won't bore you with the details.)

I tried checking the icon ID of the padlock button instead of the cantdelete property of the card, but that didn't work, either. I also tried On doMenu...

I see from the docs that I can't trap the deleteCard message. And, in fact, the deleteCard message doesn't seem to appear in the message watcher. So it's not surprising that the script doesn't work.

The way it works now, if the cantdelete of the card is set to true and I choose "Delete Card" from the "Object" menu, I get the "are you sure you want to delete this card?" message, but nothing happens when I choose "Yes." The on deleteCard script seems to be ignored entirely.

I suppose one approach would be to set the cantdelete of all cards to true, forget about using the Delete Card menu item, and to make a "delete card" button instead. But maybe there's a better way.


Thanks,

Tim

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Fri Jun 29, 2007 9:08 am

Hi Tim,

Probably, a Revolution script prevents you from handing the deleteCard message yourself. I'd consider this a Rev bug.

Note the remark in the docs: The actual deletion is not triggered by the deleteCard message, so trapping the message and not allowing it to pass does not prevent the card from being removed.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Timothy
Posts: 78
Joined: Tue Apr 11, 2006 7:38 pm

Post by Timothy » Fri Jun 29, 2007 7:16 pm

Hi Mark,

Thanks for your help. I hadn't thought of this issue as a bug, but I did wonder why it's not possible to trap deleteCard. Maybe there's a good reason for it, but none has occurred to me, or you.

I was surprised to find what happens if you choose "Delete Card" from the object menu when the cantdelete of the card is set to true. You get the "are you sure you want to delete this card" dialog from Rev, but nothing happens when you click on "Yes." Ideally, in that case, Rev would put up a dialog box that said, "Can't delete protected card," or words to that effect.

This might not rise to the level of a bug, but is inelegant and slightly user hostile.

It looks like you can't trap "newcard" either, and I suppose there are several similar issues.


Cheers,


Tim

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Fri Jun 29, 2007 7:22 pm

Hi Tim,

It seems you have found at least 3 bugs. Could you please report them to the QCC and post the bug numbers here?

Thanks!

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply

Return to “Talking LiveCode”