注册 登录
编程论坛 Delphi论坛

菜鸟请教关于对话框的程序!

delphi_zhang 发布于 2010-04-22 21:03, 775 次点击
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var i:word;
begin
i:=MessageDlg('是否要关闭该窗口?',mtConfirmation,[mbYes,mbNo],1);
if i=6           //为什么是6,而不是1或0?
then CanClose := true
else CanClose := false;


end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
showmessage('窗口马上关闭了!');
action:=cafree;          //这句什么意思?
end;
2 回复
#2
mohao1632010-04-23 09:22
这里边i是MessageDlg的返回值,MessageDlg我也没研究过,这段代码可以改写为:
if MessageDlg('是否要关闭该窗口?',MB_YESNO or MB_ICONQUESTION or MB_DEFBUTTON2) = IDYES then
CanClose := true
else
CanClose := false;

Delphi中MDI子窗口的关闭方式默认为缩小而不是关闭,所以当你单击子窗口右上角的关闭按钮时会发觉该子窗口只是最小化,而不是你预期的那样被关闭。解决办法是在子窗口的OnClose事件处理过程中加入如下代码,示例:

procedure ChildForm.OnClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;


caFree是delphi MID子窗口的关闭模式
Delphi为一个Form的关闭行为指定了四种方式,分别是:
caNone 禁止Form被关闭
caHide Form不被关闭,但是被隐藏。被隐藏的Form仍然可以被程序访问。
caFree Form被关闭,并且释放其占用的资源。
caMinimize Form被最小化而不是被关闭,这是MDI子窗口的默认关闭行为。

#3
shuang2009112010-04-26 12:14
Value    Numeric value    Meaning

IDOK    1    The user chose the OK button.
IDCANCEL    2    The user chose the Cancel button.
IDABORT    3    The user chose the Abort button.
IDRETRY    4    The user chose the Retry button.
IDIGNORE    5    The user chose the Ignore button.
IDYES    6    The user chose the Yes button.
IDNO    7    The user chose the No button.

6表示点击了YES button
1