Description
The ModalResult
property lets you obtain or set the form’s dialog result.
By default, ModalResult
is mrNone
. If the form is displayed using the ShowModal
method, setting the ModalResult
property to anything other than mrNone
causes the form to close. When the user presses the form button whose ModalResult
property differs from mrNone
, the same value is automatically assigned to the form’s ModalResult
property. You can also set the value of this property from the script code in order to close the form.
Declaration
Applies To
The property is applied to the following object:
Property Value
One of the following constants defined in the BuiltIn
object:
Constant | Value | Description |
---|---|---|
mrNone |
0 | None. |
mrOk |
1 | The dialog result is OK. |
mrCancel |
2 | The dialog result is Cancel. |
mrAbort |
3 | The dialog result is Abort. |
mrRetry |
4 | The dialog result is Retry. |
mrIgnore |
5 | The dialog result is Ignore. |
mrYes |
6 | The dialog result is Yes. |
mrNo |
7 | The dialog result is No. |
mrAll |
8 | The dialog result is All. |
mrNoToAll |
9 | The dialog result is No To All. |
mrYesToAll |
10 | The dialog result is Yes To All. |
Example
The following example checks which form button was pressed to close the form. It assumes that the current project contains the form named TestForm with OK and Cancel buttons. The buttons’ModalResult
property should be mrOK
and mrCancel
respectively.
JavaScript, JScript
function Test()
{
var form = UserForms.TestForm;
form.ShowModal();
// Check which form button was pressed
if (form.ModalResult == mrOk)
ShowMessage ("The OK button was pressed.");
else
ShowMessage ("The Cancel button was pressed.");
}
Python
def Test():
form = UserForms.TestForm
form.ShowModal()
# Check which form button was pressed
if (form.ModalResult == mrOk):
ShowMessage ("The OK button was pressed.")
else:
ShowMessage ("The Cancel button was pressed.")
VBScript
Sub Test
Set form = UserForms.TestForm
form.ShowModal
' Check which form button was pressed
If form.ModalResult = mrOk Then
ShowMessage ("The OK button was pressed.")
Else
ShowMessage ("The Cancel button was pressed.")
End If
End Sub
DelphiScript
procedure Test;
var form: OleVariant;
begin
form := UserForms.TestForm;
form.ShowModal;
// Check which form button was pressed
if form.ModalResult = mrOk then
ShowMessage ('The OK button was pressed.')
else
ShowMessage ('The Cancel button was pressed.');
end;
C++Script, C#Script
function Test()
{
var form = UserForms["TestForm"];
form["ShowModal"]();
// Check which form button was pressed
if (form["ModalResult"] == mrOk)
ShowMessage ("The OK button was pressed.");
else
ShowMessage ("The Cancel button was pressed.");
}
See Also
Working With User Forms in Tests
UserForm.ShowModal Method
TcxButton.ModalResult