on startup and on shutdown

Graham Samuel graham.samuel at wanadoo.fr
Sun Jan 11 10:20:39 EST 2004


On Sun, 11 Jan 2004 08:19:00 -0500, Thomas J McGrath III 
<3mcgrath at adelphia.net> wrote:

>I just found the on startup and on shutdown handlers. I have tried to
>clean up my CD project by putting the initializers into these handlers.
>The docs say that is what they are for.
>
>Has anyone used these that much? I don't think they load when the stack
>is launched in the IDE. I think they only run in the final build.
>Does anyone know for sure? I had to put the code in both the startup
>and preopen stack handlers. In the preopenstack I put an 'if the
>environment is "development" then do the same code as in the startup
>handler.
>
>Also related to this, I was reading the docs and they say if you want
>to keep a preference set to load the variables into a custom property
>on shutdown and then reload the custom prop into the variable on start
>up. I have not been successful in this in my CD. Also, I thought from
>this list that the only way to save info was via a separate stack
>outside the build. Seems a contradiction.
>
>Has anyone done this? I need to test it in a simple stack.

Hi Tom

I always use a startup handler to initialise globals and other settings for 
the whole program, because it seems a very neat way to do it in the final 
app. I put the handler in the stack script of my first stack (usually a 
splash screen which acts as the repository for my common routines). It is 
true that it doesn't work in the IDE (presumably when the IDE is started it 
swallows the startup message on its own account), but you can get round 
that by typing

  send "startup" to stack "mySplash"

into the Message Box: another technique I have used is to have a button on 
a card which is only used during my development cycle (contains timing 
data, private logs and such) which just executes the script above. Late in 
the development cycle this card gets hidden or sent offscreen, but can be 
brought back easily enough if users report bugs.


The shutdown handler is invoked during the quit sequence, and in fact 
'shutdown' and 'shutDownRequest' are the only ways AFAIK to handle any 
shutdown actions you might want to perform under OSX, since the actual 
'Quit' menu item is taken out of your hands by the OS. It seems to me that 
'shutDownRequest' is superior to 'shutDown' because this gets sent when the 
OS demands that the application quits, at least on Mac systems (don't know 
how this differs from handling the aevtquit Apple Event, but that's another 
story).

I have no experience with custom property sets, but clearly the technique 
you mention will only work for a non-read-only stack, otherwise all changes 
will be lost...

HTH

Graham


---------------------------------------------------
Graham Samuel / The Living Fossil Co. / UK & France  




More information about the use-livecode mailing list