Archived

This topic is now archived and is closed to further replies.

Objects in DLLs

This topic is 5580 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have classes in a dll and I want to use the objects of the classes in the dll in my application. The dll and the app are developed using delphi. How do I export the class or methods in a class that are in a DLL and how do I use it in the exe? I cannot write: var Class1 : TClass1 exports Class1.mymethod; or exports TClass1.mymethod. I have tried exports Class1; and it is exports it in the dll, but how do I use it?

Share this post


Link to post
Share on other sites
It sure does work for C++, but the problem in Delphi is that when we use an unit, the implementation in also compiled into the exe. I donot want the dll unit in the exe, is there any way?

Share this post


Link to post
Share on other sites
Exporting classes in Delphi is a bit different than in C++.

If you dont want the exe to have the dll class imbedded in it, you have to define an class with virtual methods(or an interface), then have a helper function to create the said class.

When you do get the classes in the DLL to export, there are some issues you have to be aware of. This is were the enhanced functionality that each class offers breaks. All objects desend from a Tobject class. But the exe & dll each contain a copy of the class structures. Thus the exe.Tobject is different from the dll.Tobject. Thus the functions are used to implement the keywords is &as will fail then you mix classes form the exe & the dll.

ie "Tobject is GetDllTobject.Tobject"
This will always be false. (the function GetDllTobject should just return the class referenace to Tobject and be exported by the dll).

The reason for this is the class refereance is actually a pointer, and the is &as keywords work by transversing a linked list searcing for the pointer. But since the dll & exe version occupy different places in memory, the search will fail.

This could be fixed by on loading a dll, patching the object references. But this would be fail if the host dll wasnt a delphi exe. But packages already do this, but require a delphi app to work.

[edited by - ggs on September 1, 2002 2:20:31 AM]

Share this post


Link to post
Share on other sites
Or you could have a look at my Plugin system which could give you anwer to your question.

http://groups.yahoo.com/group/bsoft

I will be posting a new version of it soon with source and article of how to use it. It''s written in delphi but it can be used with other languages when I have written converted interfaces for c++.

Share this post


Link to post
Share on other sites