TobjectList between exe and DLL in Delphi

烈酒焚心 提交于 2019-12-18 09:34:49

问题


can somebody confirm me that it is not possible to exchange between an exe and a dLL written in Delphi a pointer that contains a TobjectList?

Class definition shared between DLL and EXE
TCMStack = CLASS(TObject)
PRIVATE
FEquipment: TCMEquipment;         /// equipement with associated constraints
FNbCoils: integer;                  /// coils used
FListeCoils: TCoilsList;            ///coil list associaed with a stack
....

in executable code:

...
/// Transfer business information to optimisation module
/// fOptimisation is a instance of class 
fOptimisation.TransfererDonneesMetiersDansOptimisation(@TStack, LEVEL_OPTIM_1, false);

The content of @TStack in good except the TobjectList


回答1:


You cannot pass Delphi objects across a module boundary unless you are using runtime packages. So, between a DLL and an EXE, it is not possible.

The reason for this restriction is that in order to pass objects across module boundaries you need to share the types between the modules. And that's not possible with a DLL and an EXE. The sharing of types between different modules is the primary functionality of runtime packages.

The documentation explains the limitation like this:

Libraries are significantly more limited than packages in what they can export. Libraries cannot export constants, types, and normal variables. That is, class types defined in a library will not be seen in a program using that library. To export items other than simple procedures and functions, packages are the recommended alternative. Libraries should only be considered when interoperability with other programming is a requirement.

If you must use DLLs then you need to find some other way to interop. One good option is to use interfaces.



来源:https://stackoverflow.com/questions/15504047/tobjectlist-between-exe-and-dll-in-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!