Custom Properties
Richard Gaskin
ambassador at fourthworld.com
Wed Apr 12 21:13:05 EDT 2006
Mark Wieder wrote:
> What this lets me do is subclass from existing objects
> (in this case a field) to create a new ledger field
> object, and then duplicate and reuse it.
A word of caution for newcomer jumping into getProp and setProp, to save
them some gray hairs I earned a couple weeks ago:
The docs note that if you handle a property setting for an object, and
in that setProp also set a property of the same name, the call to set
the property from within the setProp handler won't trigger another
setProp, e.g.:
setProp MyProp pMyVal
set the MyProp of me to pMyVal
end MyProp
This prevents recursion, since if the setProp did trigger another
setProp you'd be stuck in an infinite loop.
However, setting other properties other than the one being handled will
trigger a setProp for that other property:
setProp MyProp pMyVal
set the MyOtherProp of me to pMyVal --triggers setProp MyOtherProp
end MyProp
Now here's the tricky part: the no-recursion feature only kicks in if
the handler is in the target object itself. I learned this the hard way
by moving my getProps and setProps to a library and then wondering why
I was getting recursion errors.
So if you want to centralize your getProp and setProp handlers, you can
do so safely if the true name of any property you set isn't the same and
the property which triggered the setProp:
-- Library version of first example:
on setProp MyProp pMyVal
set the _MyProp of the target to pMyVal
end MyProp
Hope that was clear enough to be helpful....
--
Richard Gaskin
Managing Editor, revJournal
_______________________________________________________
Rev tips, tutorials and more: http://www.revJournal.com
More information about the use-livecode
mailing list