OnCloseQuery (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

When you attempt to close the form in this example, a message asking if it OK to close the form appears. If you press the OK button, the form closes. If you press Cancel, the form does not close. Populate the OnCloseQuery event handler of the form.

Code

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  if MessageDlg('Close the form?', mtConfirmation,
    [mbOk, mbCancel], 0) = mrCancel then
     CanClose := False;
end;

Uses