procedure CreateMyForm(const FormClassName, FormName : string);
begin
if Application.FindComponent(FormName)=nil then begin
if GetClass(FormClassName) <> nil then
with TForm(TComponentClass(FindClass(FormClassName)).Create(Application)) do begin
Name := FormName;
Show;
end
else ShowMessage(Format('类%s未注册',[FormClassName])); end
else begin
ShowMessage(Format('窗体%s已创建过',[FormName]));
TForm(Application.FindComponent(FormName)).Show;
end;
end;
procedure CreateMyForm(const FormClassName, FormName : string);
begin
if GetClass(FormClassName) <> nil then
with TForm(TComponentClass(FindClass(FormClassName)).Create(Application)) do begin
if FindComponent(Name)<> nil then Name := FormName;
Show;
end
else
ShowMessage(Format('类%s未注册',[FormClassName]));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
CreateMyForm('TForm2', 'Form4');
end;
procedure LoadFrom(const FormName: string);
begin
if TForm1.ClassNameIs(FormName) then
Form := TForm1.Create(nil)
else if TForm2.ClassNameIs(FormName) then
Form := TForm2.Create(nil)
...
else raise Exception.Create('Invalid FormName');
end;