跟一般的 DLL 差不多的:
比如
1,包中包含的单元:
unit testu;
interface
function test;
exports
test; //输出该过程
implementation
function test;
var
i: Integer;
begin
i := 100;
end;
end.
2,包的源文件(编译生成 pkgtest.bpl):
package pkgtest;
{$R *.RES}
...//省略一些编译指令
{$IMPLICITBUILD OFF}
contains
testu in 'testu.pas';
end.
3,调用 pkgtest 中的 test 过程:
type
Ttest = procedure;
procedure TForm1.Button1Click(Sender: TObject);
var
HPackage: THandle;
test: Ttest;
begin
HPackage := LoadPackage('pkgtest.bpl');
if (HPackage <> 0) then
try
@test := GetProcAddress(HPackage, 'test');
if (@test <> nil) then
test
else
RaiseLastWin32Error;
finally
UnLoadPackage(HPackage);
end
else
RaiseLastWin32Error;
end;