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;
可以建立一个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;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin CanClose:=ID_YES = Application.MessageBox( '确定关闭吗?' '请确认', MB_ICONQUESTION + MB_YESNO MB_SYSTEMMODAL); end;
OnCloseQuery中处理即可http://lysoft.7u7.net
procedure TForm1.btn1Click(Sender: TObject); var i:integer; begin i:=messagebox(handle,'确定要关闭吗?','提示',MB_OKCANCEL); if i=2 then {什么事也不做就可以啦.} end; 根据跟踪得出,messagebox的cancle按纽的返回值是2(在xp中),当然,不推荐用这种方法,因为系统可能会变.
呵呵,楼上(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
if Application.MessageBox('a','b',MB_OKCANCEL) = IDOK then begin end;
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; 我感觉这个比较对
if MessageDlgPos('修改信息尚未保存,是否保存',mtConfirmation, mbYesNoCancel, 0, 200, 200) = IDCancel then Abort;
begin
if MessageDlgPos('Are you there?',mtConfirmation, mbYesNoCancel, 0, 200, 200)=mrYes then
CanClose:=True
else
CanClose:=False;
end;
如果保存了,就让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;
begin
CanClose:=ID_YES = Application.MessageBox(
'确定关闭吗?' '请确认', MB_ICONQUESTION + MB_YESNO MB_SYSTEMMODAL);
end;
var
i:integer;
begin
i:=messagebox(handle,'确定要关闭吗?','提示',MB_OKCANCEL);
if i=2 then
{什么事也不做就可以啦.}
end;
根据跟踪得出,messagebox的cancle按纽的返回值是2(在xp中),当然,不推荐用这种方法,因为系统可能会变.
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
begin end;
begin
if MessageDlgPos('Are you there?',mtConfirmation, mbYesNoCancel, 0, 200, 200)=mrYes then
CanClose:=True
else
CanClose:=False;
end;
我感觉这个比较对
Abort;