Custom Properties

Mark Smith mark at maseurope.net
Thu Apr 13 05:08:15 EDT 2006


I'd forgotten about the recursion issue. It can also be avoided by  
putting a lock messages line in your setProp handler, so in your  
library example:

setProp MyProp pMyVal
   lock messages
   set the MyProp of the target to to pMyVal
end MyProp

best,

Mark

On 13 Apr 2006, at 02:13, Richard Gaskin wrote:

> 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
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list