[英]Delphi create frame that is in a package
today I've a question about frames that are in packages.今天我有一个关于包装中框架的问题。 I've a package that contains a simple frame:我有一个包含简单框架的包:
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.
I've create the package and a new projexct that use it.我已经创建了包和一个使用它的新项目。 The project has a simple form and it's code is this:该项目有一个简单的形式,它的代码是这样的:
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.
Where DIRPACK1 is the path of where the bpl is.其中 DIRPACK1 是 bpl 所在的路径。 In the "actModulo1Execute" action I would like to create the frame.在“actModulo1Execute”操作中,我想创建框架。 As you can see I get the class, but after I don't know how to instantiate the frame.如您所见,我得到了课程,但之后我不知道如何实例化框架。 Which is the manner for create the frame?创建框架的方式是什么?
For example:例如:
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;
If you don't want to use RegisterClass
then another possible way is this:如果您不想使用RegisterClass
那么另一种可能的方法是:
AClass := GetProcAddress(FPackageHandle, '@fraMain@TFrame1@');
(the convention is <at><unit_name><at><class_name><at>
). (约定是<at><unit_name><at><class_name><at>
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.