setProp and Lock messages

Mark Schonewille m.schonewille at economy-x-talk.com
Sat Dec 3 11:16:44 EST 2011


Hi Todd,

I don't quite understand your question. Surely, it is a good idea to use getProp and setProp handlers. You just need to make sure not to get trapped in a loop, but this applies to all messages. Sometimes, there is a danger that setting a property calls the setProp handler again, but locking messages prevents this from happening. A correct handler may look like this:

setProp cProp x
  lock messages
  set the cProp of the target to compress(x)
end cProp

getProp cProp
  lock messages
  return decompress(the cProp of the target)
end cProp

You need to lock messages if the target is an object on a card and the handler is at card or script level, or if the target is the card and the script is at stack level for instance.

--
Best regards,

Mark Schonewille

Economy-x-Talk Consulting and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
KvK: 50277553

Become our partner in sales http://qery.us/1bq Start selling Color Converter today. 20% commission!

On 3 dec 2011, at 17:04, Todd Geist wrote:

> Hello,
> 
> I understand that SetProp and GetProp handlers are messages and if Lock
> messages is on then these will not work.  But clearly people use GetProp
> and SetProp handlers. I see them used a lot in CustomControls. I assume the
> DataGrid uses them when you "set dgData of "….
> 
> So I am looking for clarification. When is it bad idea to use GetProp and
> SetProp handlers?
> 
> Thanks
> 
> Todd





More information about the use-livecode mailing list