如何在打开新的子窗口前,关闭已打开的所有子窗口?
thank you much.
var i : Integer
For i = (Me.MdiChildren.Length - 1) To 0 Step -1
Me.MdiChildren(i).Close()
Next i
var i : Integer
For i := 0 to MainForm.MDIChildCount-1 do
if MainForm.MDIChildren[i].Active then
MainForm.MDIChildren[i].Close;
完全同意楼上的,但补充一点,关闭的时候最好使用
FreeAndNil(Self.MDIChilden[I]);
For i := 0 to Form1.MDIChildCount-1 do
if Form1.MDIChildren[i].Active then
form1.MDIChildren[I].Close;
在每个MDI窗口的加入
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Form1 := nil; //注意这里
end;
呵呵, FreeAndNil 需要一个确定变量名
没必要用FreeAndNil
for I := MDIChildCount-1 downto 0 do
MDIChildren[I].Close;
另外在每个子窗体的OnClsoe里
Action := caFree
就OK了