Delphi 在使用exports中的方法 带参数的用法

最近项目中,需要在一个bpl中调用另一个bpl中的单元的方法, 方法如下:

在被调用的单元中定义:

procedure Inner_Ex(VoucherType: TVoucherType);

exports Inner_Ex;

实现:

procedure Inner_Ex(VoucherType: TVoucherType);

var

frm: tfrmaaa;

begin

frm := tfrmaaa.Create(Application);

try

frm.VoucherType := VoucherType;

frm.ShowModal;

finally

frm.Free;

end;

end;

在那个bpl中调用

首先:定义一个过程变量

TMyProcedure1 = procedure(x: TVoucherType); //20130927 zzf 添加

实现:

procedure Inner_Stuff;

var

Handle: THandle;

MyProcedure: TMyProcedure1;

Begin

//声明

MyProcedure := nil;

if Handle = 0 then

Handle := LoadPackage('Ple.bpl');

if Handle <> 0 then

@MyProcedure := GetProcAddress(Handle, 'Inner_Ex');

if Assigned(MyProcedure) then

///调用

MyProcedure(sNC);

end;

上面的例子就是把带参数,调用bpl方法的例子。