TFormOnClose (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example displays a message dialog box when you attempt to close the form. If you click the Yes button, the form closes; otherwise, the form only minimizes. TCustomForm. Close does not allow an action of caMinimize for a form closing itself. Close Form2 from Form1 and implement the OnClose in Form2. Place "Application.CreateForm(TForm2, Form2);" in the project dpr file to open Form2 and set the Form2 Visible property to True.

Code

void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action)
{
  TMsgDlgBtn myYes = mbYes;
  TMsgDlgBtn myNo = mbNo;
  if (MessageDlg("Close application ?", mtConfirmation, TMsgDlgButtons() << myYes << myNo,0) == mrYes)
	Action = caFree;
  else
	Action = caMinimize;
}

Uses