主窗体:
TForm1=class(TForm)
  ...
  public
    FChild:TChildForm;
  ...
  end;创建子窗体时:
if FChild <> nil then
  FChild := TChildForm.Create(self);
  ...在ChildForm的OnClose事件中:
implementation
 uses unit;//主窗体的单元.
...
TChildForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  MainForm.FChild := nil;
end;

解决方案 »

  1.   

    主窗体:
    TForm1=class(TForm)
      ...
      public
        FChild:TChildForm;
      ...
      end;
    中的FChild:TChildForm;有错,他说[Error] Unit1.pas(16): Undeclared identifier: 'FChild'
      

  2.   

    var 
      ChildForm1: TChildForm1;
    procedure TMainForm.Button1Click(...);
    begin
      if not Assigned(FindComponent('ChildForm1')) then
        ChildForm1 := TChildForm1.Create(Self)
      else if ChildForm1.WindowState = wsMaximized then
        ChildForm1.WindowState := wsNormal;
      else
        ChildForm1.Show;
    end;
      

  3.   

    这个问题以前好象有人问过,有过不少人回答,你可以去找一找。procedure TMainForm.Button1Click(...);
    begin
      TChildForm1.Create(Self);
      button1.enabled:=false;
    end;让按钮实效最简单了
      

  4.   

    最简单的办法,就是为每个子窗口编号,1,2,3,4,5
    在主窗口上放一个变量,启动这些子窗口时,先用case语句根据变量值关闭相应的窗口,同时设置这个变量值为本窗口的编号。我就是这样做的,笨是笨,但好用
      

  5.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
     newform:TForm;
     i:integer;
    begin
      with form1 do
        if mdichildcount>0 then
          for i:=mdichildcount-1 downto 1 do
            mdichildren[i].free
         else
           begin
             newform:=tform.create(self);
             newform.FormStyle:=fsmdichild;
           end;
    end;