已经在设计示图设计好窗体的外观,请问如何动态的显示这个窗口?要求分别作为模态对话框和非模态对话框显示,以及如何消毁窗口。

解决方案 »

  1.   

    非模态:
    Form2.Show;模态:
    Form2.ShowModal;
      

  2.   

    3楼都说了.Form2.Show;
    Form2.ShowModal;销毁: Form2.Free;  ( 全局的就用 FreeAndNil(Form2) )
    退出窗体(消息循环): PostQuitMessage(0);
      

  3.   

    退出应用程序(退出消息循环): PostQuitMessage(0);
      

  4.   

    这样用时:Form1.Show;
           
    Form1.Release;一切正常。如果为显示模态对话框:Form1.ShowModal;Form1.Release;关闭用Form1.Release好像有问题。请问为何?
      

  5.   

    Form1.Release;你用它干什么啊
    用这两个关闭释放不行:
    Form1.Free ;
    Form1 := nil ;
      

  6.   

    动态创建窗体:  myfrom:=TmyForm.create(nil);
      try
         myform.show; //模态则是 myform.showmodal
         {do something}
      finally
         myform.free;    
    上面的这样的效果好点,没有属主的创建窗体,自己管理生命周期.如果指定了窗体的属主,如:
    TmyForm.create(self) 和 TmyForm.create(application)..
    这些就无需显示销毁了.指定了属主,其在销毁时候一起被释放销毁了
     
      

  7.   


    谢谢大家,我已经在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;感谢大家帮我热心解答。