我正在使用 Delphi 2007,我有这种情况:
{ CommonUnit.pas }
type
// there is a callback which I want to process
TFooBar = procedure(Sender: IInterface) of object; stdcall;
// there is an interface which is used by all modules
IFoo = interface
['{0FAA4B2B-E82A-4A2A-B55F-C75EC53A1318}']
procedure Bar(Callback: TFooBar); stdcall;
end;
{ UnitInModuleCompiledWithoutPackages.pas }
type
// there is a class which implements IFoo
// and it's defined in Module One compiled without packages
TFoo = class(TInterfacedObject, IFoo)
public
// implementation is ommited
procedure Bar(Callback: TFooBar); stdcall;
end;
{ UnitInModuleCompiledWithPackages.pas }
// there is a code in Module Two compiled with packages
type
TSomeClass = class
public
// implementation is ommited
procedure SomeMethod(Sender: IInterface); stdcall;
end;
var
SomeObject: TSomeClass; // assigned by somehow
Foo: IFoo; // assigned by somehow
begin
// ...
Foo.Bar(SomeObject.SomeMethod); // so it is safe?
// ...
end;
我知道在我的情况下,如果它是这样声明的,当我试图传递一个对象引用时,这将是一个内存损坏Foo.Bar
:
type
IFoo = interface
['{0FAA4B2B-E82A-4A2A-B55F-C75EC53A1318}']
// TSomeClass now declared in CommonUnit.pas
procedure Bar(CallbackObject: TSomeClass); stdcall;
end;
这是因为TSomeClass
模块一中的实现与模块二中的不同(不同的内存管理器等)。
但是方法引用呢?
我在 Embarcadero 的文档中没有找到任何可以解决这些问题的内容。