Bill Thoen <[EMAIL PROTECTED]> wrote:
> Here's a little adventure for MapBasic people. This is a little
> game based on the classic Lady or the Tiger choice (with a Balrog
> thrown in for evil grins). But it's not just a game as it
> illustrates a problem I'm having with custom buttons and Dialog
> Remove.
>
> I have three buttons in a dialog, and each one sets the same
> (hiddeen) value in the dialog. When any of the three are pressed,
> I want the dialog dismissed and the calling function to receive a
> value based on what button was pressed. The button labeled "Door
> #1" works because it is really an OKbutton. The calling function
> for the other two is exactly the same as the one for the
> OKbutton, but it doesn't work for them. It seems that a
> CancelButton or Dialog Remove result it blowign away all the
> dialog values before you get a chance to pass them back to the
> caller. What I want to know is how do I get a custom button sub
> to dismiss a dialog without triggering a "CancelButton" event?
> dialog title "Dilemma Adventurer"
> control statictext position 4,4
> title "The odds are against you mortal! Choose a door."
> control popupmenu
> position 4, 100
> title "Lady;Tiger;Balrog"
> value 0 into iBtn
Here's the problem. "Into" clauses work *only* with
OKButtons.
Think of it this way: when a user presses a CancelButton,
he or she is saying: "Wait a minute, I changed my mind, I
don't want to do this."
It's much more difficult to back out of an action if the
process of cancelling changes variables. So MapInfo
doesn't update the variables.
The same holds true for using Dialog Remove in
ordinary Button controls: There's no way for MapInfo to
tell if that's an OK, or a Cancel. So it does the conservative
thing: It doesn't update the "Into" variables.
(You certainly can't expect
CommandInfo (CMD_INFO_DLG_OK)
to be set to ant meaningful value after a Dialog Remove,
so why should you expect it to set the Into variables?)
Granted, it would be nice if there were two flavors of
Dialog Remove: an OK-like one and a Cancel-like one.
Until then, you should use one of three schemes for
exiting from any MapBasic dialog:
Scheme #1:
This scheme is the *only* way you should use
OKButtons, CancelButtons, and Dialog Preserve.
-One OKButton and one CancelButton.
-"Into" clauses on controls that return values.
-If you need to validate control values, do it in
the handler for the OKButton. If they don't pass
the test, use Dialog Preserve.
-In your CancelButton, you *might* want to ask
the user if he/she really wants to cancel. If they
answer no, issue a Dialog Preseve.
Scheme #2:
You would be surprised how little complexity you
have to add to a dialog before you need to use
this scheme over Scheme #1. Usually, when I write
such a dialog, it goes in its own .MB file.
-Ordinary buttons only.
-dim variables for the values of your controls
at the top of your .mb file. Also dim a success/failure
variable.
-One button acts as an OK button. It validates control
values. If they're not valid, it does nothing. If they're valid,
it sets the success/failure variable to indicate "success"
and issues a Dialog Remove.
-One button acts as a Cancel button. It sets the success/failure
variable to indicate "failure" and issues a Dialog Remove.
-After the dialog, check the success/failure variable.
Scheme #3:
-Ordinary buttons only.
-One button acts as an Action button. It validates control
values. If they're valid, it performs the action the
dialog is supposed to control.
-One button acts as a "Done" button. It simply issues a
Dialog Remove.
I'll invoice you when I get an address ;)
HTH
Spencer Simpson
GIS Developer
MetroMapping Division
Baltimore Metropolitan Council
----------------------------------------------------------------------
To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put
"unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]