谢谢大家,我已经在D的帮助中找到了答案:The following methods are used for buttons in a form that is used as a modal dialog box. The methods cause the dialog box to terminate when the user clicks either the OK or Cancel button, returning mrOk or mrCancel from ShowModal, respectively. You could also set the ModalResult value to mrOk for the OK button and mrCancel for the Cancel button to accomplish the same thing. When the user clicks either button, the dialog box closes.procedure TMyDialogBox.OKButtonClick(Sender: TObject);begin ModalResult := mrOK; end;procedure TMyDialogBox.CancelButtonClick(Sender: TObject); begin ModalResult := mrCancel;end;This code brings up the modal dialog from Form1 when a button is clicked. It causes a Beep if the OK button is clicked.procedure TForm1.Button1Click(Sender: TObject);begin if MyDialogBox1.ShowModal = mrOK then Beep;end;感谢大家帮我热心解答。
Form2.Show;模态:
Form2.ShowModal;
Form2.ShowModal;销毁: Form2.Free; ( 全局的就用 FreeAndNil(Form2) )
退出窗体(消息循环): PostQuitMessage(0);
Form1.Release;一切正常。如果为显示模态对话框:Form1.ShowModal;Form1.Release;关闭用Form1.Release好像有问题。请问为何?
用这两个关闭释放不行:
Form1.Free ;
Form1 := nil ;
try
myform.show; //模态则是 myform.showmodal
{do something}
finally
myform.free;
上面的这样的效果好点,没有属主的创建窗体,自己管理生命周期.如果指定了窗体的属主,如:
TmyForm.create(self) 和 TmyForm.create(application)..
这些就无需显示销毁了.指定了属主,其在销毁时候一起被释放销毁了
谢谢大家,我已经在D的帮助中找到了答案:The following methods are used for buttons in a form that is used as a modal dialog box. The methods cause the dialog box to terminate when the user clicks either the OK or Cancel button, returning mrOk or mrCancel from ShowModal, respectively. You could also set the ModalResult value to mrOk for the OK button and mrCancel for the Cancel button to accomplish the same thing. When the user clicks either button, the dialog box closes.procedure TMyDialogBox.OKButtonClick(Sender: TObject);begin
ModalResult := mrOK;
end;procedure TMyDialogBox.CancelButtonClick(Sender: TObject);
begin
ModalResult := mrCancel;end;This code brings up the modal dialog from Form1 when a button is clicked. It causes a Beep if the OK button is clicked.procedure TForm1.Button1Click(Sender: TObject);begin
if MyDialogBox1.ShowModal = mrOK then
Beep;end;感谢大家帮我热心解答。