procedure TForm1.FormCreate(Sender: TObject);
var
  ARttiContext: TRttiContext;
  ARttiPackage: TRttiPackage;
begin
  ARttiContext := TRttiContext.Create;
  for ARttiPackage in ARttiContext.GetPackages() do
  begin
    if SameText(ExtractFileName(ARttiPackage.Name), 'TEST.BPL') then
    begin
      ARttiInstanceType := ARttiPackage.FindType('Unit2.TFORM2') as TRttiInstanceType;
      if ARttiInstanceType <> nil then
      begin
      begin
        Frm := ARttiInstanceType.MetaclassType.Create as TForm;
        Frm := Frm.Create(Application);
        Frm.Show;
      end;
      Break;
    end;
    Application.ProcessMessages;
  end;
end;

在调用前别忘记加载包文件LoadPackage('Form2.bpl');

posted on 2015-04-03 13:22  delphi老中医  阅读(993)  评论(0编辑  收藏  举报