How to select line of an option btn in modal stack [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
Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

How to select line of an option btn in modal stack [SOLVED]

Post by Zax » Fri Apr 15, 2016 4:47 pm

Hello,

I would like to show a substack as modal, but I have to populate and select a specified line of an option button before displaying this stack.
Of course, the option button is on the substack to be shown as sheet.
I've got this error:
Type Chunk: can't select object that isn't open
...
This is my code:

Code: Select all

lock messages
show this stack
... [populate some fields]
... [populate the option button named for this example "OptionButton"]
select line myValue of btn "OptionButton"
sheet stack (the short name of this stack)
Thanks for your help.
Last edited by Zax on Sun Apr 17, 2016 10:35 am, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: How to select line of an option button in modal stack

Post by dunbarx » Fri Apr 15, 2016 6:03 pm

Hi.
I would like to show a substack as modal, but I have to populate and select a specified line of an option button before displaying this stack.
Of course, the option button is on the substack to be shown as sheet.
I do not understand. I assume the stack IS shown before the option button is populated, etc.?

Craig Newman

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

Re: How to select line of an option button in modal stack

Post by Zax » Sat Apr 16, 2016 9:29 am

dunbarx wrote:I do not understand. I assume the stack IS shown before the option button is populated, etc.?
The substack is closed (and removed from memory) before the script is called:

Code: Select all

lock messages
show this stack -- here the stack is shown but not visible
set title of this window to myWindow
... [populate some fields] -- OK
... [populate the option button named for this example "OptionButton"] -- OK
select line myValue of btn "OptionButton" -- this line makes the error (all is fine without this line, but my option button is not set as it should be
sheet stack (the short name of this stack) -- the substack is show and appears like a modal dialog
EDIT:
I made a mistake, the command should be:

Code: Select all

select menuItem [integer] of btn "OptionButton"
In order to choose this item.

In HTML, it would be :

Code: Select all

<select name="xxxNom" id="xxxID" size="10>
		<option value="xxxValeur" selected="selected">xxxOption1</option>
	</select>
But I have the same error :(

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: How to select line of an option button in modal stack

Post by jacque » Sat Apr 16, 2016 8:41 pm

There is a mechanism in place to do this kind of thing. LC has an always-present variable called "the dialogData" which is specifically for passing information to a modal dialog, though you can use it to store any kind of data temporarily for any reason. It is volatile and likely to change at any time, much like the variable "it" or "the result", so you should populate it right before you open a modal stack and use the values immediately.

To use it, set the dialogData to the values the modal stack will need right before you issue the "sheet" command. In the substack that will become the modal dialog, use a preOpenCard handler to grab the values and set up the display. How you pass the values is up to you; sometimes just a comma-delimited string of values is enough. Or you might use an array, or name/value pairs, or anything else.

For example, in the main handler that will display the modal:

Code: Select all

put myWindow into item 1 of tValues -- window title
put myValue into item 2 of tValues -- option button selection
set the dialogData to tValues
sheet (the short name of this stack)
And in a preOpenCard handler of the sheet stack:

Code: Select all

on preOpenCard
  get the dialogData
  set the title of this stack to item 1 of it
  lock messages
  set the menuhistory of btn "optionButton" of me to item 2 of it -- typical way to handle menu setup
  unlock messages
end preOpenCard

The reason to lock messages before setting menuHistory is because a menuPick message is sent automatically when the history changes, which you probably don't want to happen during initialization.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

Re: How to select line of an option button in modal stack

Post by Zax » Sun Apr 17, 2016 10:34 am

It works just as expected :)
I didn't know the "dialogData" variable.

Thank you very much Jacqueline.

Post Reply