if not Assigned(form1) then form1 := tform1.create(self); form1.show;或者 if form1 = nil then form1 := tform1.create(self); form1.show;
给你一个通用函数:procedure OpenForm(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;这样你每次调用即可:如: OpenForm(TfrmChild1,frmChild1, self);别忘了在close的时候: Action:=caFree;
使用下面的函数就行了 procedure OpenForm(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(Application); form1.show;
form1 := tform1.create(self);
form1.show;或者
if form1 = nil then
form1 := tform1.create(self);
form1.show;
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;这样你每次调用即可:如: OpenForm(TfrmChild1,frmChild1, self);别忘了在close的时候: Action:=caFree;
procedure OpenForm(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;
form1 := tform1.create(Application);
form1.show;