我的代码,很简单的:
unit aa;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TMytest = class(TForm)
RadioButton1: TRadioButton;
CheckBox1: TCheckBox;
GroupBox1: TGroupBox;
Panel1: TPanel;
Edit1: TEdit;
private
{ Private declarations }
public
procedure register;
{ Public declarations }
end;
var
Mytest: TMytest;
implementation
{$R *.dfm}
{ TMytest }
{ TMytest }
procedure TMytest.register;
begin
RegisterClass(Tmytest);
end;
end.
我把这个Form做成BPL。
然后用这段代码来调用:
procedure TForm1.Button1Click(Sender: TObject);
var
PackageModule: HModule;
regproc: procedure();
AClass: TPersistentClass;
begin
PackageModule := LoadPackage('d:/temp/bpltest/Package1.bpl');
if PackageModule <> 0 then
begin
RegProc:= GetProcAddress(PackageModule,Pchar('@Aa@Register$qqrv'));//载入包中的函数
if Assigned(RegProc) then
begin
regproc();//调用函数
end;
AClass := GetClass('TMytest');
if AClass <> nil then
with TComponentClass(AClass).Create(Application)
as TCustomForm do
begin
ShowModal;
Free;
end;
end;
UnloadPackage(PackageModule);
end;
但就是不行。