procedure ShowForm(FormClass: TFormClass;var fm;showtype:integer); 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 showtype=0 then Child.Show else Child.ShowModal; if Child.WindowState=wsMinimized then Child.WindowState:=wsNormal; Child.BringToFront; Child.Setfocus; tform(fm):=Child; exit; end; child:=formclass.Create(application); tform(fm):=child; if showtype=0 then Child.Show else Child.ShowModal; end; 参数: FormClass:窗体类名,如Tform1, fm:窗体名,如form1, showtype:有无模式,0为无模式窗体,1为模式窗体。给分吧。
最简单直观的: //procedure mainform.showform1Click if form1=nil then Application.CreateForm(Tform1,form1); form1.Show; //procedure form1.close; Action := caFree; form1 := nil;
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 showtype=0 then
Child.Show
else
Child.ShowModal;
if Child.WindowState=wsMinimized then
Child.WindowState:=wsNormal;
Child.BringToFront;
Child.Setfocus;
tform(fm):=Child;
exit;
end;
child:=formclass.Create(application);
tform(fm):=child;
if showtype=0 then
Child.Show
else
Child.ShowModal;
end;
参数:
FormClass:窗体类名,如Tform1,
fm:窗体名,如form1,
showtype:有无模式,0为无模式窗体,1为模式窗体。给分吧。
//procedure mainform.showform1Click
if form1=nil then
Application.CreateForm(Tform1,form1);
form1.Show;
//procedure form1.close;
Action := caFree;
form1 := nil;