用onCloseQuery事件:
procedure TfrmMain.FormCloseQuery(Sender: TObject
var CanClose: Boolean);
var
rt: longint;
begin
rt:= MessageBox(Self.Handle, PChar('Close?'), PChar('CloseQuery'), MB_OKCANCEL);
if rt = IDCANCEL then
CanClose:= False
else
CanClose:= True;
end;