I am using Delphi 2007 and I have this case:
{ 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 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;
I know that this will be memory corruption in my case when I try to pass a reference to an object in Foo.Barif it is declared as follows:
type
IFoo = interface
['{0FAA4B2B-E82A-4A2A-B55F-C75EC53A1318}']
// TSomeClass now declared in CommonUnit.pas
procedure Bar(CallbackObject: TSomeClass); stdcall;
end;
This is because the implementation TSomeClassin Module One is not the same as in Module Two (different memory managers, etc.).
But what about the link method?
I did not find anything in the Embarcadero documentation that could clarify this.
source
share