问题
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:
- 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.
- Continue to use DLLs, but access the types via interfaces rather than Delphi classes. Interfaces, unlike classes, can be exported across DLL boundaries.
- 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