Empty fields and controls after testing

Peter M. Brigham, MD pmbrig at gmail.com
Wed Oct 26 21:52:27 CDT 2011


One way that works to initialize controls (fields, pop-up buttons, menus, etc) is to store a set of default values as a customproperty containing an array with the keys being the names of the controls and the values being the contents. For instance store your default button/menu contents in the initialStateButtons of the stack, default field contents in the initialStateFields of the stack (each containing an array), then on preopenstack fetch the initial state props, step through the keys of the arrays, and load the contents. You have to be sure to name your controls with unique names, but that's good practice anyway.

And I use customprops themselves to store data of various kinds, so to initialize a stack properly I have to delete (or set to default values) various customprops, too.

It's a bit of a pain to set all this up, but more tedious than difficult, and once you've done it, it works like a charm.

-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig


On Oct 26, 2011, at 6:18 PM, Pete wrote:

> Gotta think about other types of controls too, like option menus, etc.
> 
> Maybe it's just the type of applications I tend to write but I want a lot of
> my stacks to retain their data from last time they were closed and not
> re-initialise them.
> 
> For example, I have a stack that lists a bunch of accounts in a datagrid
> (populated from an SQL db) and users can filter the accounts by account
> type. Then when the user clicks on an account, they get various information
> about it in other controls, plus a second datagrid gets populated with the
> latest transactions in the selected account.
> 
> When the stack is opened, I want the user to see what what displayed to them
> at the time they last closed the stack so I re-populate the accounts
> datagrid based on whatever filters they had in place when the stack was
> closed (in case any new accounts got added, etc), select the accounts
> datagrid row they had selected when the stack was closed, etc, etc.  I guess
> that's still a form of initialisation.
> 
> Most of the time, I only want to initialise controls in my stack to empty or
> some other value when it's designed to insert a new entry into the db.  For
> that type of stack, I initialise the controls to the default value defined
> in the database for the SQL column related to the control, taking into
> account option menu choices, etc.
> 
> 
> Pete
> Molly's Revenge <http://www.mollysrevenge.com>
> 
> 
> 
> 
> On Wed, Oct 26, 2011 at 2:43 PM, Ken Ray <kray at sonsothunder.com> wrote:
> 
>> 
>> On Oct 26, 2011, at 11:19 AM, Bob Sneidar wrote:
>> 
>>> Yes, you will need to write your own initialization routine. I do this
>> anyway in all my forms because I read data into the fields, and then
>> validate before writing them back to my storage. I always want to make sure
>> I do not have any random data from a previous edit session making it's way
>> into my database. Usually I have a populate handler that when passed empty
>> for the arguement instead of a string or array, it puts empty into all my
>> fields. Then I just call the populate handler when I open the form,
>> typically in preOpenCard.
>> 
>> 
>> One thing to be careful about - NEVER do this (unless you are 100% sure):
>> 
>> on preOpenCard
>> repeat with x = 1 to the number of fields
>>   put empty into field x
>> end repeat
>> end preOpenCard
>> 
>> It seems reasonable, but what it will do is to empty out your label fields
>> as well, which can be a real PITA to put back again. It's always better
>> (IMHO) to either address the fields you want to clear *directly*, like:
>> 
>> on preOpenCard
>> put "FirstName,LastName,Age" into tFields
>> repeat for each item tField in tFields
>>   put empty into field tField
>> end repeat
>> end preOpenCard
>> 
>> OR, set some kind of custom property on the fields you want to clear (or
>> protect), or at least make sure you walk carefully on fields that have their
>> lockText turned on (which is what label fields have by default), like:
>> 
>> on preOpenCard
>> repeat with x = 1 to the number of fields
>>   if the lockText of field x is false then
>>     if the short name of field x is not among the items of
>> "PrefilledField, DefaultCity" then
>>       put empty into field x
>>     end if
>>   end if
>> end repeat
>> end preOpenCard
>> 
>> Just my 2 cents…
>> 
>> Ken Ray
>> Sons of Thunder Software, Inc.
>> Email: kray at sonsothunder.com
>> Web Site: http://www.sonsothunder.com/
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
>> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode




More information about the use-livecode mailing list