setProp and Lock messages

Richard Gaskin ambassador at fourthworld.com
Sat Dec 3 16:53:13 EST 2011


Using getProp and setProp seem like good choices initially, since they
allow us to make what might appear to be reasonably simple,
property-driven code.

But -

They are tricky, for many reasons.

You've identified the most commonly-discussed issue:  preventing
recursion by locking messages.

But there's a bigger issue:  if any other script has the lockMessages
set while triggering any action which would normally trigger a getProp
or setProp, your getProp/setProp won't happen.

For these reasons, I've pretty much lost interest in getProp and
setProp, in favor of more broadly-reliable and explicit methods of doing
things, even if these alternatives seem a bit less fashionable:

I just use accessor handlers.  Nothing fancy, just explicit calls to
commands and functions to get and set values and trigger other behaviors
where once upon a time I might have used getProp/setProp.

Extra bonus points: it often requires less typing as well. :)

getProp/setProp can still be very useful when you need to work on
specific control instances and want the behavior to be bypassed whenever
lockMessages is true.  In that rare case, getProp/setProp are unbeatable.

But for everything else, I tend to use simple accessors....

-- 
  Richard Gaskin
  Fourth World
  LiveCode training and consulting: http://www.fourthworld.com
  Webzine for LiveCode developers: http://www.LiveCodeJournal.com
  LiveCode Journal blog: http://LiveCodejournal.com/blog.irv




More information about the use-livecode mailing list