Empty fields and controls after testing

Pete pete at mollysrevenge.com
Wed Oct 26 18:18:06 EDT 2011

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.

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

More information about the Use-livecode mailing list