为什么我在formclose事件中加入如下代码,然后点击否,也退出程序那?
begin
  if application.messagebox('确实要退出吗?','',mb_yesno+mb_iconinformation)=mryes then
  application.terminate;
end;

解决方案 »

  1.   

    procedure TFrmMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
      if mrNo = MessageDlg('确实要退出吗?', mtConfirmation, [mbYes, mbNo], 0) then
        Abort
      else
      begin
        CloseForm();
      end;
    end;
      

  2.   

    begin
      if application.messagebox('确实要退出吗?','',mb_yesno+mb_iconinformation)=mryes then
      application.terminate
    else
    Action:=caNone;
    end;
      

  3.   

    你可以看看OnClose事件的帮助说明,这个是关闭窗口的时候触发,而OnCloseQuery是试图关闭的时候触发!所以使用OnCloseQuery事件
      

  4.   

    dulei115() 和FrameSniper(人类不能不吃饭@手机不能不充电.net)
    都说了揭贴吧
      

  5.   

    才看你的代码不好意思。
    procedure TFrmMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
    if application.messagebox('确实要退出吗?','',mb_yesno+mb_iconinformation) 
      =IDyes then
      application.terminate;
    end;
    mryes改为idyes
      

  6.   

    procedure TFrmMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    var 
    i:integer;
    begin
    i:=application.messagebox('确实要退出吗?','',mb_yesno);
    if i=IDyes then
      application.terminate;
    end;
      

  7.   

    procedure TFrmMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
      if mrNo = MessageDlg('确实要退出吗?', mtConfirmation, [mbYes, mbNo], 0) then
        Abort
      else
      begin
        CloseForm();
      end;
    end;