在一个MDI中,如何通过一个按纽来关闭所有已经打开的窗体(主窗体除外)。
注:其它打开的窗体并不是MDI的子窗体。

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      i : Integer;
    begin
      for i:= 0 to Application.ComponentCount -1 do
        if Application.Components[i] is TForm then begin
          if Application.Components[i]<>Application.MainForm then
            TForm(Application.Components[i]).Close; //or free
        end;end;
      

  2.   

    procedure TfrmMain.CloseAllMdiWindow;
    var i:integer;
    begin
      for i:=0 to FrmMain.MDIChildCount-1 do
      begin
        if frmMain.MDIChildren[i].Active then
          FrmMain.MDIChildren[i].Close;
      end;
    end;
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      i : Integer;
    begin
      for i:= 0 to Application.ComponentCount -1 do
        if Application.Components[i] is TForm then begin
          if Application.Components[i]<>Application.MainForm then
            TForm(Application.Components[i]).Close; //or free
        end;end
      

  4.   

    var
     i:integer;
    begin
      for i:=0 to screen.FormCount-1 do
        if screen.Forms[i]<>application.MainForm then
          screen.Forms[i].Close;
    end;
      

  5.   

    注:其它打开的窗体并不是MDI的子窗体。
    ************************************
    那这些窗体是不是你所说的“主窗体”所属程序创建的呢? ________________________欢迎访问和宣传我的论坛http://hthunter.vicp.net/