|
<< 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".
|
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)

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.

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


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

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

3.Describe the button event processing.
Write the following code in the OnMouseUp event of the button.

The contents to be written are the following three lines.
if( button == 1 ){ |
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.
|
For details about the OnMouseUp event, see "OnMouseUp". |
|
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.

Then, the OnCommonEvent event was added to the script editor.

Write the following code in the OnCommonEvent event of the button.

The contents to be written are the following three lines.
if( value == T ){ |
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.

Then, a script for the OnTerminate event was added to the script editor.

Write the following code in the button's OnTerminate event.

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.

If you click the "No" button, the dialog box just closes and nothing happens.
Clicking the "Yes" button will exit Panel Browser.
|
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. |