on closeStack [Solved]

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
antrax13
Posts: 39
Joined: Mon Jun 01, 2015 11:38 am

on closeStack [Solved]

Post by antrax13 » Wed Sep 02, 2015 10:04 am

Hi all,

its me again with funny issues :lol:

I have the main stack where I put the connection/disconnection on openStack/closeStack.

Code: Select all

on openStack
connectDB
end openStack
then I want to close connection when the stack is closed so I have

Code: Select all

on closeStack
closeDatabaseConnection
end closeStack
Now the issue is I have couple of cards and some substacks but as soon as I close substackit will disconnect me from database because it will run closeStack that is on mainstack script.

So is there any function like on closeMainStack or to have:

if "only the particular name of the stack" is closed then closeconnection else do not close connection end if

The code that I need, must be on main stack script

In other words how can I close connection when the main stack is closed not substack
Last edited by antrax13 on Wed Sep 02, 2015 10:53 am, edited 1 time in total.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: on closeStack

Post by jmburnod » Wed Sep 02, 2015 10:33 am

Hi antrax13,
if "only the particular name of the stack" is closed then closeconnection else do not close connection end if
Yes you're right, you can check the name of stack like a condition
You can also use pass closestack if you want do something on closestack for the current stack and pass closestack

Best regards
Jean-Marc
https://alternatic.ch

antrax13
Posts: 39
Joined: Mon Jun 01, 2015 11:38 am

Re: on closeStack

Post by antrax13 » Wed Sep 02, 2015 10:44 am

jmburnod wrote:Hi antrax13,
if "only the particular name of the stack" is closed then closeconnection else do not close connection end if
Yes you're right, you can check the name of stack like a condition
You can also use pass closestack if you want do something on closestack for the current stack and pass closestack

Best regards
Jean-Marc
could you help me with syntax because I have

Code: Select all

on closeStack
   if stack "TestingStack" is closed then
      answer "mainstack has been closed"
      --closeDatabaseConnection
   else
      answer "substack has been closed"
   end if
end closeStack
is giving me error stack "TestingStack": execution error at line 8 (Chunk: source is not a container), char 1 ===> Line 8 is if stack "TestingStack".....

antrax13
Posts: 39
Joined: Mon Jun 01, 2015 11:38 am

Re: on closeStack

Post by antrax13 » Wed Sep 02, 2015 10:53 am

OK got it

Code: Select all

on closeStack
   put the short name of this stack into tStackName
   if tStackName is "TestingStack" then
      answer "mainstack has been closed"
      closeDatabase
   else
      answer "substack has been closed"
   end if
end closeStack

antrax13
Posts: 39
Joined: Mon Jun 01, 2015 11:38 am

Re: on closeStack [Solved]

Post by antrax13 » Wed Sep 02, 2015 11:06 am

Just checking with me colleague and he also suggested another solution to have empty

Code: Select all

on openStack
   
end openStack

on closeStack
   
end closeStack
on substacks

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: on closeStack [Solved]

Post by bn » Wed Sep 02, 2015 11:18 am

Hi Antrax

the problem here is that when you close a substack the substack gets a message "closestack". Since the substack apparently does not handle this message the message travels along and finds in the message path the main stack, which has a closeStack handler.

If your substack includes a

Code: Select all

on closestack
end closestack
handler in the stack script the message would stop there and never reach the main stack.

Of course Jean-Marc's approach is perfectly alright and might in some circumstances be the only way. E.g. the mainstack has to do something when the substack closes.

This is just to remind you of the message path which can at times surprise

Kind regards
Bernd

Post Reply