procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if MessageDlg('你想关闭窗体?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
canclose:=true
else canclose:=false;
end;
在窗体的close事件中添加代码
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if messagedlg('确信要退出吗?',mtConfirmation,[mbyes,mbno],0)<>mryes then
action:=canone;
end;