在窗体的onclose事件中加入
if messagedlg('您要关闭文件吗?',mtconfirmation,[mbyes,mbno],0)<>idyes then 
  ....

解决方案 »

  1.   

    在OnCloseQuery事件中
      if messagedlg('您要关闭文件吗?',mtconfirmation,[mbyes,mbno],0)<>idyes then 
      ....
      

  2.   

    if messagedlg('您要关闭文件吗?',mtconfirmation,[mbyes,mbno],0)<>idyes then 
    Action:=caNone ;Action的值:
    Value MeaningcaNone The form is not allowed to close, so nothing happens.
    caHide The form is not closed, but just hidden. Your application can still access a hidden form.
    caFree The form is closed and all allocated memory for the form is freed.
    caMinimize The form is minimized, rather than closed.To close the form and free it in an OnClose event, set Action to caFree.
      

  3.   

    上面的写在窗体的onclose事件中
      

  4.   

    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
      

  5.   

    如果只是响应窗体上的X及系统菜单的关闭,可以响应WM_SYSCOMMAND消息的SC_CLOSE子消息,详见MSDN(我98下的MSDN坏了,没法查)