Create a confirmation dialog for quitting using Simple Common Dialog

<< Click to Display Table of Contents >>

Manual > Screen Creation Guide > Forms and Dialogs/Frames/Views > Common Dialog > Simple Common Dialog >

Create a confirmation dialog for quitting using Simple Common Dialog

overview

In many cases where a simple common dialog is displayed, it is necessary to prompt the operator for some kind of confirmation, such as a yes/no confirmation. In addition, some kind of input may be made to the simple common dialog, such as a calendar selection or password check. In these interactive simple common dialogs, it is necessary to receive the processing results of the simple common dialog in some way for the subsequent processing of the dialog caller.

 

The processing results on the dialog side can be received via an event called OnCommonEvent. Here, we will explain how to use the simple common dialog and how to receive processing results via OnCommonEvent, using as an example how to display a confirmation screen for closing using the simple common dialog's "OpenYesNoMsg".

 

hint

The information that can be received in the OnCommonEvent parameters varies depending on the type of simple common dialog. For details, see the descriptions of each of the common methods in "Simple Common Dialogs" in the Control Reference.

 

 

Create a confirmation dialog for quitting using Simple Common Dialog

This is an example of creating a system shutdown confirmation dialog using the simple common dialog "OpenYesNoMsg".

 

(Exit confirmation dialog)

fap_dialog_0062

 

In this example, we will add Button control to the form and display an exit confirmation dialog (Yes/No) when the button is clicked.

If the answer is Yes, Panel Browser will be terminated; if the answer is No, the process will be canceled.

 

 

1.Paste Button control into the form.
 
tra_0439
 

2.Add a OnMouseUp event to the button.
 
Select the Button object and click the Script tab to display the Script Editor.
 
tra_0440
 
tra_0441
 

 

Select "OnMouseUp(button)" from the event combo box in the upper left of the script editor.

 

tra_0442
 

 
The OnMouseUp event has been added to the script editor. The processing content is written within the range enclosed in curly brackets “{” “}”.
 
tra_0443
 

 

 

3.Describe the button event processing.
 
Write the following code in the OnMouseUp event of the button.
 
tra_0444
 
 
The contents to be written are the following three lines.
 

   if( button == 1 ){
::OpenYesNoMsg(this, "Do you want to exit?");
   }

 
The "button == 1" written above determines whether the left mouse button was clicked. The "button" of the OnMouseUp event passes which mouse button was used for mouse up (whether the mouse was clicked and released) when the event occurred. The value of button is "1" for the left mouse button, "2" for the middle button, and "3" for the right button.

 

The "::OpenYesNoMsg..." statement is the process for calling a simple common dialog.

Here, the processing result of the OpenYesNoMsg dialog will be notified to the OnCommonEvent event of the object specified in the first argument. In the above example, because "this" is specified, the OnCommonEvent event of the object in which the script is written, that is, the button object, will be called. Also, the string specified in the second argument will be displayed as a message in the dialog.

 

hint

For details about the OnMouseUp event, see "OnMouseUp".

 

hint

For details about the simple common dialog calling method "OpenYesNoMsg", please refer to the common method "OpenYesNoMsg".

 

 

4.Describes the processing to be performed when Yes is pressed.
 
Select "OnCommonEvent(name, value)" from the event combo box in the upper left of the script editor.
 
tra_0445
 
 
Then, the OnCommonEvent event was added to the script editor.
 
tra_0446
 
 
Write the following code in the OnCommonEvent event of the button.
 
tra_0447
 
 
The contents to be written are the following three lines.
 

   if( value == T ){
       ::CloseBrowser();
   }

 
The above processing means that if the condition "value == T" is met, then "::CloseBrowser()" will be processed.
 
OnCommonEvent is designed to be called when the Yes/No button on the simple common dialog is pressed. When the event is called, whether Yes or No was pressed is entered into the value variable as TRUE/FALSE. In other words, "value == T" (T is an abbreviation for TRUE) is the conditional expression for when the Yes button is pressed on the simple common dialog.
 
Also, "::CloseBrowser()" is the root method that closes Panel Browser.
 

 

5.Describe the process to close the common dialog.
 
If the screen that called the common dialog is switched to another screen while the common dialog is still displayed, only the common dialog will remain displayed. Therefore, when using a common dialog, be sure to write a process to close the dialog itself in the event (OnTerminate) that occurs when the button that called the dialog is destroyed.
 
Therefore, add the "OnTerminate" event to the button and write the process to close the common dialog.
 
First, select "OnTerminate()" from the event combo box in the upper left of the script editor.
 
tra_0448
 
 
Then, a script for the OnTerminate event was added to the script editor.
 
tra_0449
 
 
Write the following code in the button's OnTerminate event.
 
tra_0450
 
 
The content to be written is the following single line.
 

   ::CloseYesNoMsg();

 
The above "::CloseYesNoMsg()" is a process for closing the simple common dialog "YesNoMsg".

 

This completes the event description.
 

 

Due to the above process, the following confirmation dialog will be displayed when you click the button.

 

fap_dialog_0062

 

If you click the "No" button, the dialog box just closes and nothing happens.

Clicking the "Yes" button will exit Panel Browser.

 

 

attention

Do not close the form that contains the object specified in target (the object specified in the first argument of the OpenYesNoMsg method) before closing the common dialog. If there is a possibility that it may be closed, close the common dialog in the OnTerminate event of that object. This process ensures that the common dialog is automatically closed when the form that contains target is closed. If this process is not implemented, when the common dialog is closed after the parent form is closed, the target object will no longer exist and the dialog will be closed automatically.Application errors may occur.