Accessing classes that are in another DLL?

北城以北 提交于 2020-02-15 10:05:57

问题


Is there is a way of exporting and using classes from another dll, I have 2 dll's and I am trying to access classes in between, was wondering if this is possible.


回答1:


There are a variety of ways to achieve this, including but not limited to the following:

  1. Use runtime packages rather than DLLs. Then you can use any types, variables, etc. from another module. Note that this forces you to use runtime packages in all of your modules, and to compile all of the modules with the same version of Delphi.
  2. Continue to use DLLs, but access the types via interfaces rather than Delphi classes. Interfaces, unlike classes, can be exported across DLL boundaries.
  3. Continue to use DLLs, but access the types using unit scope procedures and functions rather than classes. This would lead you to an interface of the same nature as the Win32 interface.

Of the above options, they are arranged in order of decreasing convenience. The most convenient is to use runtime packages but that may place an undesirable constraint on you that all modules are compiled with the same Delphi version. Interfaces are usually more convenient to consume than a Win32 style interface, but there may be more programming overhead in setting up such an architecture. You'll have to make the choice that you feel best suits your needs.

If you can avoid using separate modules in the first place, and build everything into a single executable file, then that is far and away the most convenient approach.



来源:https://stackoverflow.com/questions/34851618/accessing-classes-that-are-in-another-dll

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