CloseReason: FormCloseReason;
The CloseReason property returns the reason of form closing.
Executing the example requires a form. The specified procedure is set for the form as a handler of the OnCloseQuery event.
Sub FormOnCloseQuery(Sender: Object; Args: ICloseQueryEventArgs);
Var
b: Boolean;
Begin
If Args.CloseReason = FormCloseReason.UserClosing Then
b := WinApplication.ConfirmationBox(
"If this form closes, all unsaved data will be lost. Are you sure you want to close the form?");
Args.Allowed := b;
End If;
End Sub FormOnCloseQuery;
When the event occurs, the cause of form closing is determined. If the user tries to close the form, the confirmation dialog box opens. If the Yes button is pressed in the dialog box, the form closes.
See also: