用什么方法判断MDI程序中的MDIChild窗体已经创建,并不让它重复创建?

解决方案 »

  1.   

    如果form2是子窗体则创建时候添加如下代码
    if not assigned(form2) then
      form2:=tform2.create(application);
      

  2.   

    procedure OpenForm(FormClass: TFormClass; var fm; AOwner:TComponent);
    var
      i: integer;
      Child:TForm;
    begin
      for i := 0 to Screen.FormCount -1 do
          if Screen.Forms[i].ClassType=FormClass then
          begin
            Child:=Screen.Forms[i];
            if Child.WindowState=wsMinimized then
               ShowWindow(Child.handle,SW_SHOWNORMAL)
            else
               ShowWindow(Child.handle,SW_SHOWNA);
            if (not Child.Visible) then Child.Visible:=True;
            Child.BringToFront;
            Child.Setfocus;
            TForm(fm):=Child;
            exit;
          end;
      Child:=TForm(FormClass.NewInstance);
      TForm(fm):=Child;
      Child.Create(AOwner);
    end;
      

  3.   

    var
      Form1: TForm1;implementation
     uses unit2;
    {$R *.dfm}procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
    if not assigned(form2) then
    form2:=tform2.create(application);
    form2.Show;
    end;这样不可以么,你想达到什么目的??
      

  4.   

    请问楼上的,Assigned函数有何作用,为什么现在一个都创建不了???
      

  5.   

    if not assigned(form2) then...
    就是判断当前是否已经创建了form2这个mdichild型的子窗体,如果没有则创建!
      

  6.   

    func system.assigned(Const P) 本身好象无返回值
      

  7.   

    function Assigned(const P): Boolean;
    Description
    Use Assigned to determine whether the pointer or procedure referenced by P is nil. P must be a variable reference of a pointer or procedural type. Assigned(P) corresponds to the test P<> nil for a pointer variable, and @P <> nil for a procedural variable.
    Assigned returns false if P is nil, true otherwise.
    上面一句对这个函数说得已经很清楚了,如果参数p空则函数返回值为false,反之为true
      

  8.   

    procedure TmainFrm.mnuIncaseClick(Sender: TObject);
    var incaseFrm : TincaseFrm;
    begin
      if Not Assigned(incaseFrm) then
        incaseFrm := TincaseFrm.Create(Application);
      incaseFrm.Show;
    end;不过先谢了。
      

  9.   

    局部变量声明有问题, incaseFrm 应该是全局变量
      

  10.   

    把var incaseFrm : TincaseFrm;这句去掉,在implementation后面uses这个单元就可以了
      

  11.   

    哎,但这样的话,第一次使用完关闭后,第二次就打不开了: 异常:Abstract Error!
      

  12.   

    哦?不是把,你再在form2的onclose事件里面加上form2:=nil;这样应该没问题了