CloseStack, CloseStackRequest don't run in standalone

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Simon Knight
Posts: 845
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

CloseStack, CloseStackRequest don't run in standalone

Post by Simon Knight » Tue Mar 16, 2021 9:47 am

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
2021-03-16-083041-Screenshot 2021-03-16 at 08.30.35.png (31.43 KiB) Viewed 2654 times


What have I misunderstood?
Thanks
Simon
best wishes
Skids

Simon Knight
Posts: 845
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: CloseStack, CloseStackRequest don't run in standalone

Post by Simon Knight » Tue Mar 16, 2021 9:52 am

....and don't try this

Adding waits
2021-03-16-085030-Screenshot 2021-03-16 at 08.50.25.png
The IDE gets very unhappy when trying to build the standalone

S
best wishes
Skids

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: CloseStack, CloseStackRequest don't run in standalone

Post by jmburnod » Tue Mar 16, 2021 10:05 am

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
https://alternatic.ch

Simon Knight
Posts: 845
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: CloseStack, CloseStackRequest don't run in standalone

Post by Simon Knight » Tue Mar 16, 2021 6:36 pm

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
best wishes
Skids

Simon Knight
Posts: 845
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: CloseStack, CloseStackRequest don't run in standalone

Post by Simon Knight » Wed Mar 17, 2021 12:08 pm

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
best wishes
Skids

Post Reply

Return to “Talking LiveCode”