Page 1 of 1
CloseStack, CloseStackRequest don't run in standalone
Posted: Tue Mar 16, 2021 9:47 am
by Simon Knight
Hi,
I have a utility application (i.e. pretty rough for my own use only!) that saves data to a preference file. The preferences are loaded in a preopenstack handler and this all works.
I'm having problems with triggering the save preferences file and have tried both the closeStack and closeStackRequest handlers with the same result : they are called while in the IDE but do not get called from a standalone version. I feel that I have missed something very obvious.....
Here is my most recent handler, borrowed from the dictionary, which is in the main stack :
Code: Select all
on closeStack
UpdatePreferenceFile
answer "Are you sure you wish to quit DZ Rename?" with "No" or "Yes"
if it is "Yes" then pass closeStack
end closeStack
I have also tried the suspendstack message with the same result.
The file does use both sub stacks and a single library stack :

- 2021-03-16-083041-Screenshot 2021-03-16 at 08.30.35.png (31.43 KiB) Viewed 3539 times
What have I misunderstood?
Thanks
Simon
Re: CloseStack, CloseStackRequest don't run in standalone
Posted: Tue Mar 16, 2021 9:52 am
by Simon Knight
....and don't try this
Adding waits
The IDE gets very unhappy when trying to build the standalone
S
Re: CloseStack, CloseStackRequest don't run in standalone
Posted: Tue Mar 16, 2021 10:05 am
by jmburnod
Hi Simon,
I think you have to add this scriot in your stack script
Code: Select all
on closeStack
if there is a stack "revStandaloneProgress" then
if the mode of stack "revStandaloneProgress" > 0 then
exit closeStack
end if
else
pass closeStack
end if
end closeStack
Here is explanation about it
search.php?keywords=revStandaloneProgress
Best regards
Jean-Marc
Re: CloseStack, CloseStackRequest don't run in standalone
Posted: Tue Mar 16, 2021 6:36 pm
by Simon Knight
Hi Jean-Marc,
Thanks for the link, it certainly points towards the issue although I still don't understand what is going on. There is another issue in that my startusing substack calls which are in the preopenstack handler are not being called or don't place the substack scripts into the message path.
More head scratching required!
I may even have to read the release documentation.
best wishes
Simon
Re: CloseStack, CloseStackRequest don't run in standalone
Posted: Wed Mar 17, 2021 12:08 pm
by Simon Knight
So this is what was occurring and it was all my fault (surprise!)
The preferences file was causing an error : I used an absolute path to describe a field which meant that when the standalone processed it the filepath to the stack was wrong because the the standalone was in a different folder. The standalone did not have any error traps so the startUsing message was never called. This meant that the calls made from the closeStack handler also generated an un-trapped error in the standalone because the handlers being called were in a substack that was not in the message path. The result was code that worked in the IDE but not in the build.
The solution was to reformat the data in the preference file using stack names rather than IDs and also to add "try" "catch" statements to catch any errors.
Here are the new close/quit handlers which I have placed in card 1 which is the only card:
Code: Select all
on closeStackRequest
-- if the mode of stack "revStandaloneProgress" > 0 then
-- exit closeStackRequest
-- end if
try
WritePreferenceFile
pass closeStackRequest
catch tError
answer "An error occurred in CloseStackRequest : " && tError
pass closeStackRequest
end try
end closeStackRequest
on shutdownRequest
try
WritePreferenceFile
pass shutdownRequest
catch tError
answer "An error occurred in handler : shutdownRequest : " && tError
pass shutdownRequest
end try
end shutdownRequest
The three lines that are commented out are copied from the release notes for LC version 9.0 and are intended for the CloseStack message. If they are uncommented they prevent the closeStackRequest from completing in the final standalone application.
So the problem is solved with a reason code of "idiot at the wheel!"
best wishes
Simon