Variable transfers Between Stacks and Sub-Stacks.

Eric Chatonet eric.chatonet at sosmartsoftware.com
Thu Mar 29 08:10:43 EDT 2007


Hello Simon,

There are many ways to handle user preferences and I assume that  
you'll get many different ideas from the list.
Here is one where used stacks are assumed read-only and current prefs  
stored out of any stack:

Default standard prefs are stored in a custom property set.
This is handy since a custom property set can easily be put into a  
global array* or combined to be written to a file, a db record, etc.
If current prefs are not found, a file, a record, etc. is created  
from this custom property set and a prefs global array fed.
If a prefs file (or another way of storing them) is found, the global  
array is just fed with it**.
When the Prefs substack is open, values in the array are used to set  
up the layout accordingly.
Every change in the prefs modifies some value in the array.
When appropriate, the global array (possibly combined) is saved.
Actually xml could be used to store prefs but it might appear that a  
simple tab/tab/return list easily converted to an array or to/from a  
custom property set makes things a lot easier.

* put the customProperties["cDefaultPrefs"] of <object> into gPrefs  
where <object> can be 'this stack' or 'button "Prefs" of card "Prefs"  
of stack "Prefs"' or whatever fits your needs. This oneliner will  
feed the array as expected.
** Of course, a validity check of each pref value is preferable:  
Boolean, integer(s), text value, etc.
If a pref does not match an expected format or appears empty, the  
default pref should be restored.

Hope this helps.
Best regards from Paris,

Eric Chatonet.

Le 29 mars 07 à 13:31, Simon HARPER a écrit :

> Hi there,
>
> So I've a main stack and sub-stack for preferences. I save and load  
> the variables as a stack (not text of xml - just yet) when I open  
> and close the substack. However, is there best practice for how to  
> load the variables on startup of the mainstack and then use them in  
> the mainstack - refereshing if people change the preferences (in  
> the sub-stack) while the application is running?
>
> I'm sure this must be done a lot but I wonder if there is an  
> accepted best way. Also, would I just define a global variable for  
> inter-stack variables?
>
> Cheers
> Si.
>
> ====
> Simon Harper

----------------------------------------------------------------
http://www.sosmartsoftware.com/
eric.chatonet at sosmartsoftware.com/
----------------------------------------------------------------





More information about the use-livecode mailing list