我在mainForm中双击treeview菜单创建child窗体。
现在的问题是:点一次就创建一次child窗体实例。我只想存在一个child窗口实例。不希望创建多个实例。
package1中包含了test.pas.  Ttestpp = class(TForm); testpp: Ttestpp;实做代码:
        LoadPackage('Pkgtest.bpl');
        if TFormClass(FindClass('Ttestpp')) <> nil then
        begin
          try
            TFormClass(FindClass('Ttestpp')).Create(self);
          finally
            
          end;
        end;

解决方案 »

  1.   

    procedure TMainForm.NewMyFormClick(Sender:TObject);
    var
       i : Integer
    Begin
       For i := 0 To MDIChildCount-1 do
          if MDIChildren[i] is TMyForm then 
          begin
              MDIChildren[i].BringToFront;
              Exit;
          End;   Application.CreateForm(TMyform,Myform);
    end;
      

  2.   

    if not Assigned(Form1) then
       Form1:=TForm1.Create(Application);
    Form1.show;
      

  3.   


    IF  not  Assigned(Form1) then 
    Form1:= TForm1.Create(self)
    else
    Form1.Show ;
      

  4.   

    IF  not  Assigned(Form1) then 
    Form1:= TForm1.Create(self)
    else
    Form1.Show ;
    这种方式在我这里不好使用,因为不直接引用到form1的unit。所以使用不了form1变量。
      

  5.   

    你可以在 form1 的 unit 里写一个过程.比如:
    proceudre form1show;
    begin
      if form1 = nil then tform1.create....
    end;
      

  6.   

    to maple119():你这样处理还是需要use Form1的unit啊。
      

  7.   

    to maple119():你这样处理还是需要use Form1的unit啊。当然要呀,你没继承单元,怎么创建你要的类?
      

  8.   

    获取VForm类。(我有数据来源)。为了不应用Form类,我把Form类存在别的数据中,然后获取的。后用这个函数来判断了。问题解决就行了,不过感觉应该有简单的方法。
    function IsAlreadForm(vForm: string): boolean;
    var
      i: integer;
    begin
      result := false;
      for i := 0 to application.MainForm.MDIChildCount - 1 do
      begin
        if string(application.MainForm.MDIChildren[i].classname) = vForm then
        begin
          application.MainForm.MDIChildren[i].BringToFront;
          result := true;
          exit;
        end;
      end;
    end;