我使用了如下代码,但是无论点是还是否程序都会退出,请解题。
procedure TMainFrm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if Application.MessageBox('真的要退出吗?', '提示', MB_YESNO+MB_ICONQUESTION) = ID_no then
exit;
end;
procedure TMainFrm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if Application.MessageBox('真的要退出吗?', '提示', MB_YESNO+MB_ICONQUESTION) = ID_no then
exit;
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := false;
if Application.MessageBox('ÕæµÄÒªÍ˳öÂð£¿', 'Ìáʾ', MB_YESNO+MB_ICONQUESTION) = ID_no then
exit
else
CanClose := true;
end;
iUserResp :integer;
iUserResp := MessageBox(Handle,'真的要退出吗?','提示', MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON1);
Case iUserResp of
IDYES:
begin
end;
IDNO:
begin
end;
end;
但是请问 allan2002(丸子) 为什么如楼主或者其他回答者的方法不行呢?
begin
if Application.MessageBox('真的要退出吗?', '提示', MB_YESNO+MB_ICONQUESTION) = ID_no then
CanClose:=false
else
CanClose:=true;
if CanClose then Application.terminate;
end;
简单点儿说其实就是在楼主的代码开始和结束各加一条语句,形如:
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := false;
if Application.MessageBox('真的要退出吗?', '提示', MB_YESNO+MB_ICONQUESTION) = ID_no then
exit;
CanClose := true;
end;