如果文件未保存,点击了关闭按钮,由下面豫剧给出提示MessageDlgPos('修改信息尚未保存,是否保存',mtConfirmation, mbYesNoCancel, 0, 200, 200);如何才能实现,档选择取消时又恢复到原界面;
谢谢

解决方案 »

  1.   

    procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
     if MessageDlgPos('Are you there?',mtConfirmation, mbYesNoCancel, 0, 200, 200)=mrYes then
       CanClose:=True
     else
       CanClose:=False;
    end;
      

  2.   

    可以建立一个Bool变量,比如Modified
    如果保存了,就让Modified为False,否则就是 True;
    procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    var
      I: Integer;
    begin
     if not Modified then 
        CanClose := True
     else
     begin 
       I := MessageDlgPos('Are you there?',mtConfirmation, mbYesNoCancel, 0, 200, 200);
       if I = mrYes then
         CanClose := True
       else
         CanClose := False;
      end;
    end;
      

  3.   

    procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
       CanClose:=ID_YES = Application.MessageBox(
    '确定关闭吗?' '请确认', MB_ICONQUESTION + MB_YESNO         MB_SYSTEMMODAL);
    end;
      

  4.   

    OnCloseQuery中处理即可http://lysoft.7u7.net
      

  5.   

    procedure TForm1.btn1Click(Sender: TObject);
    var
      i:integer;
    begin
      i:=messagebox(handle,'确定要关闭吗?','提示',MB_OKCANCEL);
      if i=2 then
      {什么事也不做就可以啦.}
    end;
    根据跟踪得出,messagebox的cancle按纽的返回值是2(在xp中),当然,不推荐用这种方法,因为系统可能会变.
      

  6.   

    呵呵,楼上(cancel的返回值肯定是2)
    mrNone 0 None. Used as a default value before the user exits.
    mrOk 1 The user exited with OK button.
    mrCancel 2 The user exited with the CANCEL button. 
    mrYes 3 The user exited with the YES button.
    mrNo 4 The user exited with the NO button.
    mrAbort 5 The user exited with the ABORT button.
    mrRetry 6 The user exited with the RETRY button.
    mrIgnore 7 The user exited with the IGNORE button.
    mrAll 8 The user exited with the ALL button.
    mrNoToAll 9 The user exited with the NO TO ALL button.mrYesToAll 10 The user exited with the YES TO ALL button
      

  7.   

    if Application.MessageBox('a','b',MB_OKCANCEL) = IDOK then
      begin  end;
      

  8.   

    procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
     if MessageDlgPos('Are you there?',mtConfirmation, mbYesNoCancel, 0, 200, 200)=mrYes then
       CanClose:=True
     else
       CanClose:=False;
    end;
    我感觉这个比较对
      

  9.   

    if MessageDlgPos('修改信息尚未保存,是否保存',mtConfirmation, mbYesNoCancel, 0, 200, 200) = IDCancel then
    Abort;