//OnCloseQuery
procedure TForm1.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
if MessageDlg('Close the form?', mtConfirmation,
[mbOk, mbCancel], 0) = mrCancel then
CanClose := False;
end;
//OnClose
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
if MessageDlg('Close application ?', mtConfirmation,
[mbYes, mbNo], 0) = mrYes then
Action := caFree
else
Action := caNone;
end;