unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2, Unit3;
{$R *.dfm}
function f(mName: string): Boolean;
var
FormClass: TFormClass;
begin
Result := True;
try
FormClass := TFormClass(FindClass(mName));
with TFormClass(FormClass).Create(Application)do
try
ShowModal;
finally
Free;
end;
except
Result := False;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
RegisterClasses([TForm1, TForm2, TForm3]);
//要注册from类
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
f('TForm2');
f('TForm3');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
UnRegisterClasses([TForm1, TForm2, TForm3]);
//要注消from类
end;
end.