Passing values from a stack to its caller

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
brainois
Posts: 10
Joined: Fri Dec 01, 2006 10:19 pm

Passing values from a stack to its caller

Post by brainois » Wed Dec 13, 2006 10:20 pm

Hello,

I am rather new to Runtime Revolution and this is my first post...

I am trying to find out how to send data back from a stack to the handler that opened that stack.
The idea: a create a "Calendar" stack that is to be used to allow the user to enter a select two dates: start date and end date. This calendar can be called from different stacks/cards, therefore from different handler. When the user close the calendar stack, i would like to return the dates to the "caller". I could like to avoid using global variables...

Thanks for any tips you could give me.

Regards

François (from Belgium)

marielle
Livecode Opensource Backer
Livecode Opensource Backer

Re: Passing values from a stack to its caller

Post by marielle » Wed Dec 13, 2006 11:12 pm

brainois wrote:I am rather new to Runtime Revolution and this is my first post...
Welcome :D
brainois wrote:I am trying to find out how to send data back from a stack to the handler that opened that stack.
We discussed these issues on the use-list about a month ago. I have archived the quite long discussion on my code website at Passing parameters to other stacks.

Very many options exist. It may be easier to provide easy to follow examples if you provide some of your own code. I go for an "abstract" description here.

1. What you want is the result of a handler.

Code: Select all

send "handler_name" to stack "that_other_stack"
put the value_to_pass of stack "that_other_stack" into tValue 
in stack that_other_stack, in handler "handler_name"

Code: Select all

set the value_to_pass of me to "something"
This solution uses "customProperties"

2. What you want is the result of a function.

- put value("function_name()", stack "that_other_stack") into tValue

brainois wrote:The idea: a create a "Calendar" stack that is to be used to allow the user to enter a select two dates: start date and end date. This calendar can be called from different stacks/cards, therefore from different handler. When the user close the calendar stack, i would like to return the dates to the "caller".
Some calendar stacks can be found on Rev Online. Why not download the rev Online Picker on So Smart Software, then search for "date" or "calendar"?
brainois wrote:I could like to avoid using global variables...
And this is an excellent choice. Custom properties can be accessed from anywhere within a stack (even when substacks are included) and provide a cleaner option than global variables.

If you really need a function but are keen to use customprops, then you can always use a wrapping handler which has no function other than call the real function and store the value returned by that real function into a custom property of name "value_to_pass"

Code: Select all

on handler_name
   put handler_name() into tValue
   set the value_to_pass of me to tValue
end handler_name
--
function handler_name 
    ... actual processing taking place here ...
   return "something"
end handler_name 

brainois wrote:François (from Belgium)


Living abroad, but from Image as well (French speaking) :)

brainois
Posts: 10
Joined: Fri Dec 01, 2006 10:19 pm

Post by brainois » Fri Dec 15, 2006 10:31 pm

Thanks a lot for your detailed answer.
I think i will go for the custom properties... Much less intrusive than the global variable.

François

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”