Hello all,
I come from traditional compile - run - test cycle as many of you have. The one part of RunRev I have a question on is initialization of fields/data
For example:
I have a field that has a file name in it. For testing I click over to live and click on the link and get the file name that is puts in the field. Now when I save as a stand alone, this file name is there, instead of being just blank.
So I put that that field into a global variable. Even though the field was cleared that value is passed to the stand alone application. I hope I made sense. This can be a nightmare to debug as the variable is set but it is nowhere in your code, it just saved that state.
In everyone's opinion, what is the best way to initialize the application?
Thank you for your time.
joe
Starting Point - Application Initialization
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Starting Point - Application Initialization
A global is NOT saved. Its a temporary storage place in memory and will not be persistent.
If you stack does not have the "destroystack' property set to true, re-opening the same stack in the ide in the same session will still have the same global value because when the stack is closed it remains in memory.
If you want permanent storage of the value you can use a custom property instead. This is part of the stack itself and will carry over between sessions.
set the mySpecialFilepath of stack "stackname" to "whatevervalue"
You might look http://lessons.runrev.com/s/lessons/m/4 ... properties and look at the part about "custom properties" (read the whole thing of course too its helpful)
If you stack does not have the "destroystack' property set to true, re-opening the same stack in the ide in the same session will still have the same global value because when the stack is closed it remains in memory.
If you want permanent storage of the value you can use a custom property instead. This is part of the stack itself and will carry over between sessions.
set the mySpecialFilepath of stack "stackname" to "whatevervalue"
You might look http://lessons.runrev.com/s/lessons/m/4 ... properties and look at the part about "custom properties" (read the whole thing of course too its helpful)
Re: Starting Point - Application Initialization
Thank for you for the Global info. I think I must have click on the wrong stack when testing.
But to go to my first question. What is the best way to initialize the values in text fields. I've read some people clearing the values on save, or on stack open.
But to go to my first question. What is the best way to initialize the values in text fields. I've read some people clearing the values on save, or on stack open.
Re: Starting Point - Application Initialization
Yes, you can clear them on openstack, or closestack or opencard or closecard.
If you just want the stack to be built with empty fields you can put a handler in that clears them all out and execute it from the message box just prior to saving. If you want data in fields to be stored in the stack so that it is persistent, things get more complicated. You either have to store the states of objects into an external file or database and then reset the stack when it is re-opened, or you need to do something like this http://lessons.runrev.com/s/lessons/m/4 ... pplication Which will let you save the state of your stack (except for variables of course.)
In my particular case, I place a preopenstack handler and an openstack handler in the card script (card 1) and create handlers to init whatever i need. (So that i can break things into smaller more maneagable chunks).
Do the same for closestack. One benefit of breaking things up this way is that while in the IDE I can pick and choose which things I want to re-init or clear.
Another interesting thing you might look at is the glx framework. For what I do (quick and simple stuff) its a bit overkill, but it is pretty amazing. Even if you decided against using it, there is much to learn from it. YOu can find info on it here. http://www.bluemangolearning.com/revolu ... framework/
If you just want the stack to be built with empty fields you can put a handler in that clears them all out and execute it from the message box just prior to saving. If you want data in fields to be stored in the stack so that it is persistent, things get more complicated. You either have to store the states of objects into an external file or database and then reset the stack when it is re-opened, or you need to do something like this http://lessons.runrev.com/s/lessons/m/4 ... pplication Which will let you save the state of your stack (except for variables of course.)
In my particular case, I place a preopenstack handler and an openstack handler in the card script (card 1) and create handlers to init whatever i need. (So that i can break things into smaller more maneagable chunks).
Code: Select all
on preopenstack
handlertodostuffbeforestackshows
anotherhandlertodobeforestackshows
end preopenstack
on openstack
handlertodustoffafterstackshows
anotheronehere
end openstack
Another interesting thing you might look at is the glx framework. For what I do (quick and simple stuff) its a bit overkill, but it is pretty amazing. Even if you decided against using it, there is much to learn from it. YOu can find info on it here. http://www.bluemangolearning.com/revolu ... framework/
Re: Starting Point - Application Initialization
I am still getting my bearing with livecode but I found this in the dictionary:
When you save to standalone, if the field is not locked, will clear the field.
Thanks for the help.
When you save to standalone, if the field is not locked, will clear the field.
Code: Select all
on savingStandalone
repeat with X = 1 to the number of cards of this stack
repeat with Y = 1 to the number of fields of card X of this stack
if not the lockText of field Y of card X of this stack then
put empty into field Y of card X of this stack
end if
end repeat
end repeat
end savingStandalone