A reader asked, “When using the 2 button Notifier dialog, how do we know which button was pressed?”
The 2 button Notifier dialog alert box displays 3 buttons(!) – the first two have values you specify, such as “Ok” and “Done”, as shown here, and the third is an optional generic “Cancel” button:
The Notifier component block is a procedure call that has no return value – so how can you determine which button was selected?
The answer is that the selected button is returned to a separate event handler.
First, let us set up an example program to demonstrate. Here is a Designer view with a button “Demo the 2 button Notifier”, and two text labels, the last of which displays the content of the selected button from the Notifier:
Drag the Notifier1 component Palette to the work area; it appears beneath the work area as a “non-visible” component.
The Click event handler for the btnStartDemo button calls the Notifier’s ShowChooseDialog procedure, where we specify the text for Button 1 and for Button 2. That call displays the dialog box on screen.
After the user pressed a button, the Notifier generates an AfterChoosing event. The parameter choice contains the text of the button that was pressed.
The AfterChoosing event handler copies choice to the text label to show which button was selected. The value of choice can be compared in an if-then block to determine how the app should proceed. If the “Ok” button was pressed, then the status message is set to the color green, otherwise the text is set to blue.