"防止窗口重复创建"??mdi窗体的问题??procedure OpenChildForm(FormClass: TFormClass; var Fm; AOwner:TComponent); var i: integer; Child:TForm; begin for i := 0 to Screen.FormCount -1 do if Screen.Forms[i].ClassType=FormClass then begin Child:=Screen.Forms[i]; if Child.WindowState=wsMinimized then ShowWindow(Child.handle,SW_SHOWNORMAL) else ShowWindow(Child.handle,SW_SHOWNA); if (not Child.Visible) then Child.Visible:=True; Child.BringToFront; Child.Setfocus; TForm(Fm):=Child; exit; end; Child:=TForm(FormClass.NewInstance); TForm(fm):=Child; Child.Create(AOwner); end; //调用 OpenChildForm(TChildForm1,ChildForm1, Self);
if assigned(ChildForm) then begin ChildForm.show; ChildForm.BringToFront; end;
If Application.FindComponent('FormName')=nil then 创建窗体; 继续处理
var
i: integer;
Child:TForm;
begin
for i := 0 to Screen.FormCount -1 do
if Screen.Forms[i].ClassType=FormClass then
begin
Child:=Screen.Forms[i];
if Child.WindowState=wsMinimized then
ShowWindow(Child.handle,SW_SHOWNORMAL)
else
ShowWindow(Child.handle,SW_SHOWNA);
if (not Child.Visible) then Child.Visible:=True;
Child.BringToFront;
Child.Setfocus;
TForm(Fm):=Child;
exit;
end;
Child:=TForm(FormClass.NewInstance);
TForm(fm):=Child;
Child.Create(AOwner);
end;
//调用
OpenChildForm(TChildForm1,ChildForm1, Self);
begin
ChildForm.show;
ChildForm.BringToFront;
end;
创建窗体;
继续处理