调用时候 if Not Assigned(Form1) then Form1:=TForm1.create(Nil); Form1.show;窗体记得释放 form1.close 中加上action:=caFree; Form1.Destroy 中加上 Form1:=Nil;
给你一个函数,感谢原作者! 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;
if Not Assigned(Form1) then
Form1:=TForm1.create(Nil);
Form1.show;窗体记得释放
form1.close 中加上action:=caFree;
Form1.Destroy 中加上 Form1:=Nil;
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;