代码如下:所有的窗体都是继承来自一个窗体并且是mdi子窗体。procedure TMainForm.RzGroup7Items7Click(Sender: TObject);
var
  i:Integer;
begin
  if SmallReportForm=nil then
     try
    for i := 0 to Screen.FormCount - 1 do
    begin
      if Screen.Forms[i].FormStyle = fsMDIChild then
      begin
        CloseWindow(Screen.Forms[i].Handle);
        Screen.Forms[i].Close;
      end;
    end;
    except   end;
     SmallReportForm:=TSmallReportForm.create(nil);
  SmallReportForm.show;
end;
快了会报错

解决方案 »

  1.   

    子窗体的onclose里写了action:=cafree; 吗
      

  2.   

    有个问题你的循还越来越大,而你的FORM会越来越少,这肯定会出一现问题。如果你有9个form,当你删除第5个的时候,你再用FORMS[I] 肯定就有问题了。所以你应该用倒序循环for i:=Screen.FormCount - 1 downto 0 do
    begin
    ....
    end 
      

  3.   

    加入延时和Application.ProcessMessages;
    试试
      

  4.   

    代码如下:所有的窗体都是继承来自一个窗体并且是mdi子窗体。 procedure TMainForm.RzGroup7Items7Click(Sender: TObject); 
    var 
      i:Integer; 
    begin 
      if SmallReportForm=nil then 
        try 
        for i := 0 to Screen.FormCount - 1 do 
        begin 
          if Screen.Forms[i].FormStyle = fsMDIChild then 
          begin 
            CloseWindow(Screen.Forms[i].Handle); 
            Screen.Forms[i].Close; 
          end; 
        end; 
        except   end; 
        SmallReportForm:=TSmallReportForm.create(nil); 
      SmallReportForm.show; 
    end; 
    快了会报错 你的代码前后矛盾~~ 
    前面关闭了,后面又跟着创建~~ 代码并不矛盾