if not assigned(f) then 
f:=tinsertform.create(application);
释放f时用f.Release ;f:= nil ;(加到f的关闭事件中)

解决方案 »

  1.   

    楼上的做法只对全局变量的窗体起作用。更好的方法是:
    添加一个函数
    IsExistWindow(FormClass:TComponentClass): Boolean
    var
      iIndex: Integer;
    begin
      Result := False;
      for iIndex := 0 to MDIChildCount do begin
        if MDIChildren[iIndex] is FormClass then begin
          Result := True;
          Exit;
        end;
      end;
    end;然后在子窗体创建方法中,调用IsExistWindow函数来判断是否已经有相同类型的子窗体存在
    如:
    procedure TForm1.Button1Click(Sender: TObject);
    f:tinsertform;
    begin
      if not IsExistWindow(tinsertform) then  begin
        f:=tinsertform.create(application);
        f.Show;
      end;
    end;另:f:=tinsertform.create(application);

    f:=tinsertform.create(self);有什么区别?
    Create中的参数是宿主。表示由谁来对负责对新创建的Component的释放