function OpenForm(
const AClassName : string;
const AOwner : TComponent=nil
):TForm;
//根据窗口类名(字符串)建立窗口
var
i : integer;
frmTemp : TForm;
cmpOwner : TComponent;
begin
Screen.Cursor := crHourGlass;
try
for i := 0 to Screen.FormCount -1do
if Screen.Forms.ClassName = AClassName then
begin
frmTemp := Screen.Forms;
if frmTemp.WindowState=wsMinimized then
frmTemp.WindowState:=wsNormal;
frmTemp.BringToFront;
frmTemp.Setfocus;
Result := frmTemp;
Exit;
end;
if Assigned(AOwner) then
cmpOwner := AOwner
else
cmpOwner := Application;
Result := nil;
if Assigned(GetClass(AClassName))
and FindClass(AClassName).InheritsFrom(TForm) then
try
Result := TForm(FindClass(AClassName).NewInstance);
Result.Create(cmpOwner);
except
end;
finally
Screen.Cursor := crDefault;
end;
end;
procedure OpenForm(FormClass: TFormClass;
var AForm;
AOwner:TComponent=nil);
//根据窗口类名建立窗口,如果窗口存在则只激活它
var
i: integer;
Child:TForm;
begin
for i := 0 to Screen.FormCount -1do
if Screen.Forms.ClassType=FormClass then
begin
Child:=Screen.Forms;
if Child.WindowState=wsMinimized then
Child.WindowState:=wsNormal;
Child.BringToFront;
Child.Setfocus;
TForm(AForm):=Child;
exit;
end;
Child:=TForm(FormClass.NewInstance);
TForm(AForm):=Child;
if not assigned(aowner) then
aowner:=application;
Child.Create(AOwner);
end;