Re: Is there a way to create a generic setprop handler?

2022-08-03 Thread Richard Gaskin via use-livecode

David Epstein wrote:

> Control “A” has many custom properties that are set by a variety
> of other controls.  If Control “A” has a "setProp property1”
> handler, it can react when property1 gets set.  But is there a
> way to give Control “A” a general handler that will be triggered
> whenever any of its custom properties is set?

I don't know of a way to trap getProp and setProp generically, and that 
may not be bad since it would affect the performance of all custom 
property access, whether it's the subset of properties you're interested 
in or not.


An alternative could be to put the properties you want custom handling 
for into a custom property set of their own, e.g.:


   getPRop uPropSet[pKey]
  put the params
   end uPropSet

   on mouseUp
  get the uPropSet["key1"] of me
   end mouseUp

...puts this in the Message Box:

   uPropSet "key1"

This will allow open-ended trapping of property keys, but limited in 
scope to the set you need that for.



A word of caution with dependency on getProp and setProp:

Those messages are subject to suspension during lockMessages, which may 
be exactly what you want, or may have unintended side effects that can 
be maddening to track down if you don't keep that in mind.


Using getProp and setProp requires review of your code base, including 
any third-party libraries, which may lock messages so you can evaluate 
the implications for your circumstance.



If you need consistently reliable ways to trigger custom evaluation 
consider accessor handlers instead.  LockMessages only prevents system 
messages; calling a custom handler is not affected by lockMessages.


Examples:

-- Using an object as the value container:
on SetMyProp pKey, pVal
   set the uPropSet[pKey] of  to pVal
end SetMyProp

function GetMyProp pKey
  return the uPropSet[pKey] of 
end GetMyProp


-- Using an array variable as the value container:
on SetMyProp pKey, pVal
   put pVal into sPropVarA[pKey]
end SetMyProp

function GetMyProp pKey
  return sPropVarA[pKey]
end GetMyProp



-- Usage for either storage method:

on mouseUp
  SetMyProp "key1", "val1"
end mouseUp

on mouseUp
  put GetMyProp("key1") into fld 1
end mouseUp



Fun: If you abstract data access using normal custom handlers, you have 
one-stop-shopping to change the storage mechanism.  If you don't need 
persistence across sessions a variable may do, and if you need 
persistence you can store in an object whose stackfile gets saved, or 
encode the array variable and save that to disk, or use a local 
database, or even use any form of remote storage across the internet if 
you like -- all by updating just two handlers.



--
 Richard Gaskin
 Fourth World Systems
 Software Design and Development for the Desktop, Mobile, and the Web
 
 ambassa...@fourthworld.comhttp://www.FourthWorld.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Is there a way to create a generic setprop handler?

2022-08-03 Thread Bob Sneidar via use-livecode
If I understand you then no. The only thing I would suggest is to use dispatch 
to trigger the "general handler" in all of your virtual properties (custom 
property is not the right phrase when referring to getProp/setProp). 

Bob S


> On Aug 3, 2022, at 11:13 , David Epstein via use-livecode 
>  wrote:
> 
> Control “A” has many custom properties that are set by a variety of other 
> controls.  If Control “A” has a "setProp property1” handler, it can react 
> when property1 gets set.  But is there a way to give Control “A” a general 
> handler that will be triggered whenever any of its custom properties is set?
> 
> David Epstein

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Is there a way to create a generic setprop handler?

2022-08-03 Thread David Epstein via use-livecode
Control “A” has many custom properties that are set by a variety of other 
controls.  If Control “A” has a "setProp property1” handler, it can react when 
property1 gets set.  But is there a way to give Control “A” a general handler 
that will be triggered whenever any of its custom properties is set?

David Epstein


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode