我在菜单中写的打开子窗口事件:
form1:=tform1.create(self);
form1.show;
每次点菜单都会新建一个子窗口,能否只建一个子窗口就行了。

解决方案 »

  1.   

    if not Assigned(form1) then
      form1 := tform1.create(self);
    form1.show;或者
    if form1 = nil then
      form1 := tform1.create(self);
    form1.show;
      

  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;这样你每次调用即可:如:  OpenForm(TfrmChild1,frmChild1, self);别忘了在close的时候:  Action:=caFree;
      

  3.   

    使用下面的函数就行了
    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;
      

  4.   

    if not Assigned(form1) then
      form1 := tform1.create(Application);
    form1.show;