Delphi 创建包中的框架

Delphi create frame that is in a package

今天我有一个关于包裹中的框架的问题。 我有一个包含简单框架的包:

unit fraMain;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  Vcl.StdCtrls;

type

  TFrame1 = class(TFrame)
    Label1: TLabel;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

implementation

{$R *.dfm}

initialization
  RegisterClass(TFrame1);

finalization
  UnRegisterClass(TFrame1);

end.

我已经创建了包和一个使用它的新项目。该项目有一个简单的形式,它的代码是这样的:

unit main;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus,
  System.Actions, Vcl.ActnList, Vcl.PlatformDefaultStyleActnCtrls, Vcl.ActnMan,
  Vcl.StdCtrls;

type
  TfrmMain = class(TForm)
    mnuMain: TMainMenu;
    mnuFile: TMenuItem;
    mnuModuli: TMenuItem;
    mFilCloseModules: TMenuItem;
    mModModulo1: TMenuItem;
    mModModulo2: TMenuItem;
    N1: TMenuItem;
    mFilExit: TMenuItem;
    actManager: TActionManager;
    actExit: TAction;
    actModulo1: TAction;
    actModulo2: TAction;
    procedure actExitExecute(Sender: TObject);
    procedure actModulo1Execute(Sender: TObject);
  private
    FPackageHandle: Integer;
  public
    { Public declarations }
  end;

const
  DIRPACK1 = 'C:\Users...';

var
  frmMain: TfrmMain;

implementation

{$R *.dfm}


{ Chiusura applicazione }
procedure TfrmMain.actExitExecute(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TfrmMain.actModulo1Execute(Sender: TObject);
var
  AClass: TClass;
  AFrame: TFrame;
begin
  if FPackageHandle = 0 then begin
    FPackageHandle := LoadPackage(DIRPACK1 + 'Pack_01.bpl');
    AClass := GetClass('TFrame1');
    if AClass <> nil then begin

    end;
  end;
end;

end.

其中DIRPACK1是bpl所在的路径。 在 "actModulo1Execute" 动作中,我想创建框架。如您所见,我得到了 class,但在我不知道如何实例化框架之后。 创建框架的方式是什么?

例如:

  AClass := GetClass('TFrame1');
  if Assigned(AClass) and AClass.InheritsFrom(TCustomFrame) then
  begin
    AFrame := TCustomFrameClass(AClass).Create(Self);
    AFrame.Parent := Self;
    AFrame.Align := alClient;
    AFrame.Show;
  end;

如果您不想使用 RegisterClass 那么另一种可能的方法是:

  AClass := GetProcAddress(FPackageHandle, '@fraMain@TFrame1@');

(惯例是<at><unit_name><at><class_name><at>)。