Modal Dialog Questions

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: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Modal Dialog Questions

Post by lohill » Tue Dec 15, 2009 1:47 am

When you use a special stack and open it modally for user response, you use the modal command like:

Code: Select all

set dataDialog to tMyVar
modal "MyStack"
This opens the stack where tMyVar can be captured and dealt with in the preOpenCard event. If there is a button for finishing the dialog (and there better be), it contains code like:

Code: Select all

on mouseUp
  set the dialogData to tMyReturnVal
  close this stack
end mouseUp
Main stack execution is halted while the modal dialog is responded to by the user at which time the main stack takes over and retrieves the data that is returned with something like:

Code: Select all

put the dataDialog into tMyResult


At least this is how I understand it from the tutorial in the Developer area. My questions are:
1. Does this mean you have to have a single stack dedicated to each separate dialog you want to include in your application?
2. Is it possible to have a single stack with multiple cards each representing a distinct dialog that is used in the application? In this case the modal stack command would kick off the stack where preopenStack could determine the card for opening the desired dialog?
3. The variable dialogData is described as a global variable. Does that mean it is available anywhere in the application you want as long as you declare it within the handler where you want to use it - at least until something changes it?

I have been attempting to accomplish something like item 2, with no success and lots of confusion. Perhaps it is impossible but as I have been writing this I am beginning to think my problem might be with declaring that global in enough places. Multiple declarations of global variables is anti-intuitive for me.

Thanks in advance for any light you can shed on this.
Larry

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Modal Dialog Questions

Post by Mark » Wed Dec 16, 2009 6:08 pm

Dear Larry,

How you do it really depends on what you think is the easiest wy. If I had a number of very similar dialogs, I'd make one stack with one card, which is adjusted automatically to the type of dialog I want to show. Perhaps something like:

Code: Select all

set the dialogType of stack "My Dialog" to "List" // runs dialogType setprop handler in stack
set the dialogData to "This is a prompt" & cr & "List item 1,List item 2,List item 3,List item 4"
modal "MyDialog"
The dialogType handler might look like:

Code: Select all

setProp dialogType theType
  repeat with x = 1 to number of groups
    hide grp x
  end repeat
  show grp theType
end dialogType
the preOpenStack handler of stack "My Dialog" can now process the dialogData.

Code: Select all

on preOpenStack
  if the dialogType of me is "List" then
    put line 1 of the dialogData into fld "Prompt" of grp "List"
    put line2 of the dialogData into fld "List" of grp "List"
  else
    // do something else with the data
  end if
end preOpenStack

If I had very different dialogs, I'd avoid difficulties by using different stacks. Why do difficult if you can do it simple?

DialogData is indeed available anywhere. Just like any global property.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

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

Re: Modal Dialog Questions

Post by dunbarx » Thu Dec 17, 2009 5:24 pm

Global variables must be declared in all handlers (or scripts) that call them. Read the dictionary under "global". You will find a few shortcuts on declaring them in and out of handlers themselves, that is, in the script of the object itself.

As for counter-intuitive, I think I know what you intended, that once declared global anywhere, the engine might be able to see it universally. Not so, however.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Modal Dialog Questions

Post by Mark » Thu Dec 17, 2009 6:25 pm

Dunbar, that's not true, you're mixing RunRev and HyperCard.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply