关闭所有窗口 var LForm: array of TForm; iFormCnt,i: integer; begin iFormCnt := Application.MainForm.MDIChildCount; SetLength(LForm, iFormCnt); for i:=0 to iFormCnt-1 do LForm[i] := Application.MainForm.MDIChildren[i]; try for i:=iFormCnt-1 downto 0 do begin PostMessage(LForm[i].Handle, WM_CLOSE, 0, 0); Application.ProcessMessages; end; except end; end;
var i:integer; begin for i:=0 to MDIChildCount-1 do MDIChildren[i].Close; end;
To:楼上 var i:integer; begin for i:=0 to MDIChildCount-1 do MDIChildren[i].Close; end; 这段代码有bug,当关闭了一个窗口后,MdiChildrenCount会减1,MdiChildren[i]指向 的窗口可能已经不存在了。给人家贴代码也要自己测试通过才行,光有热心不行
To:楼上 var i:integer; begin for i:=0 to MDIChildCount-1 do MDIChildren[i].Close; end;改成: for i:=0 to MDIChildCount-1 do MDIChildren[0].Close;就可以了 ...
首先谢谢指正! var i:integer; begin for i:=0 to MDIChildCount-1 do MDIChildren[i].Close; .......再在这里把要显示的FORM给SHOW出来 end;
不过楼主这样用
不需要MDIChild
所以还是可以用ShowModal
至于只运行一次
那就只能创建某个Form之后记录他的FormClass
再打开时查找记录
有记录就不让打开了
var
LForm: array of TForm;
iFormCnt,i: integer;
begin
iFormCnt := Application.MainForm.MDIChildCount;
SetLength(LForm, iFormCnt);
for i:=0 to iFormCnt-1 do
LForm[i] := Application.MainForm.MDIChildren[i]; try
for i:=iFormCnt-1 downto 0 do begin
PostMessage(LForm[i].Handle, WM_CLOSE, 0, 0);
Application.ProcessMessages;
end;
except
end;
end;
begin
for i:=0 to MDIChildCount-1 do MDIChildren[i].Close;
end;
var i:integer;
begin
for i:=0 to MDIChildCount-1 do MDIChildren[i].Close;
end;
这段代码有bug,当关闭了一个窗口后,MdiChildrenCount会减1,MdiChildren[i]指向
的窗口可能已经不存在了。给人家贴代码也要自己测试通过才行,光有热心不行
var i:integer;
begin
for i:=0 to MDIChildCount-1 do MDIChildren[i].Close;
end;改成: for i:=0 to MDIChildCount-1 do MDIChildren[0].Close;就可以了 ...
var i:integer;
begin
for i:=0 to MDIChildCount-1 do MDIChildren[i].Close;
.......再在这里把要显示的FORM给SHOW出来
end;