例
主窗体:
TForm1=class(TForm)
...
public
FChild:TChildForm;
...
end;创建子窗体时:
if FChild <> nil then
FChild := TChildForm.Create(self);
...在ChildForm的OnClose事件中:
implementation
uses unit;//主窗体的单元.
...
TChildForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
MainForm.FChild := nil;
end;
主窗体:
TForm1=class(TForm)
...
public
FChild:TChildForm;
...
end;创建子窗体时:
if FChild <> nil then
FChild := TChildForm.Create(self);
...在ChildForm的OnClose事件中:
implementation
uses unit;//主窗体的单元.
...
TChildForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
MainForm.FChild := nil;
end;
TForm1=class(TForm)
...
public
FChild:TChildForm;
...
end;
中的FChild:TChildForm;有错,他说[Error] Unit1.pas(16): Undeclared identifier: 'FChild'
ChildForm1: TChildForm1;
procedure TMainForm.Button1Click(...);
begin
if not Assigned(FindComponent('ChildForm1')) then
ChildForm1 := TChildForm1.Create(Self)
else if ChildForm1.WindowState = wsMaximized then
ChildForm1.WindowState := wsNormal;
else
ChildForm1.Show;
end;
begin
TChildForm1.Create(Self);
button1.enabled:=false;
end;让按钮实效最简单了
在主窗口上放一个变量,启动这些子窗口时,先用case语句根据变量值关闭相应的窗口,同时设置这个变量值为本窗口的编号。我就是这样做的,笨是笨,但好用
var
newform:TForm;
i:integer;
begin
with form1 do
if mdichildcount>0 then
for i:=mdichildcount-1 downto 1 do
mdichildren[i].free
else
begin
newform:=tform.create(self);
newform.FormStyle:=fsmdichild;
end;
end;