OnCloseQuery (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

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

Code

void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)
{
  if (MessageDlg("Close the form?", mtConfirmation, TMsgDlgButtons() << mbOK << mbCancel,0) == mrCancel)
    CanClose = false;
}

Uses