Form1为MDIForm,From2为MDIChild,怎样实现:点击Form1上的Button1,如果Form2未创建就创建他,如果已创建就显示他?

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
       Application.creatform(TFomr2,Form2);
       Form2.show;
    end;
    另外,需要注意的是Form2关闭事件中
    procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
       Action:=caFree;
    end;
      

  2.   

    楼上没理解我的意思,我是要不管点多少次Button1,只生成1个Form2。你的方法是每点一次Button1就会生成1个Form2。
      

  3.   

    if not Assigned(ContactEditForm) then
        ContactEditForm := TContactEditForm.Create(Application);
      ContactEditForm.Show();
      

  4.   

    var created:boolean=False;Button onclick事件中
    if not created then
       begin
         created:=True;
         创建
       end else 显示
      

  5.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
       if for2=nil
       begin
         Application.creatform(TFomr2,Form2);
         Form2.show;
      end
      else
        Form2.show;
    end;
      

  6.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
       if form2=nil   //改正
       begin
         Application.creatform(TFomr2,Form2);
         Form2.show;
      end
      else
        Form2.show;
    end;
      

  7.   

    我一般也是这样:
    procedure TForm1.Button1Click(Sender: TObject);
    begin
       if form2=nil   
       begin
         //Application.creatform(TFomr2,Form2);
         from2 := tform.create
         Form2.show;
      end
      else
        Form2.show;
    end;
    然后在form2的destroy事件中写Form2 := nil;
      

  8.   

    if form2=nil
       begin
         Application.creatform(TFomr2,Form2);
         Form2.show;
      end
      else
        Form2.show;
      

  9.   

    if not Assigned(Form2) then
      Form2 := TForm2.Create(Application);
    Form2.show;Form2窗体OnClose里写
      Action := cafree;
    OnDestroy里写
      Self := nil;
      

  10.   

    直接CREATE就可以
    另外在子窗体的close事件里一定要释放掉action := cafree;