unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm2 = class(TForm)
    Button1: TButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

// BeginExample: TFormOnClose
// Event: Forms.TCustomForm.OnClose

// BeginCode
{
This example displays a message dialog box when the user
attempts to close the form. If the user clicks 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 (from
a button?) 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.
}
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if MessageDlg('Close application ?', mtConfirmation,
    [mbYes, mbNo], 0) = mrYes then
    Action := caFree
  else
    Action := caMinimize;
end;
// EndCode
// EndExample: TFormOnClose
end.
