PDA

View Full Version : Classes vs Dll's



NecroDOME
17-12-2006, 10:19 PM
Hi there all,

Wondering:

I have a class TDLL_GUIControl in my DLL.

Is there a way to link that class to a class in an application?

I mean:

Whiting DLL:

TDLL_GUIControl = class
private
public
RegisterSomthingFromApp;
DoSomething1;
DoSomething2;
end;


Whitin MyApp

TMyApp_GUIControl = class(TDLL_GUIControl)
private
public
RegisterSomthingFromApp;
DoSomething1; override; // override stuff?
DoSomething2;
MyOwnDoSomething;
end;


Currently I use functions like CreateButton(), CreateLabel(), SetText(), GetText(). It works nice and easy, but I was just wondering if something like I crappy described above.

technomage
17-12-2006, 11:38 PM
what you need are Delphi Packages. BUT!! Free Pascal does not support those, so what you need is something a little more indepth.

I to something similar in my current project. I define a class based API layer which just contains abstract classes.

I then override these classes in the DLL code, you can then have a special function exported from the dll to create an instance of the class and return the Abstract class type


the API

type TTestClass = class
procedure DoStuff; virtual; abstract;
end;



The DLL

type TTestClassImp = class(TTestClass)
procedure DoStuff; override;
end;


// this is the function you export
function CreateTestClass: TTestclass; cdecl;
begin
Result := TTestClassImp.Create;
end;


you should be able to figure out the rest. My solution also involved a shared memory management dll, also all the classes register themselves using a calls like Core_RegisterClass I can then use Core_GetClass to retrive the class type I'm after.

It can be done though :D

NecroDOME
18-12-2006, 09:30 AM
Thanx... will write a test program when I get home.

Setharian
18-12-2006, 04:38 PM
you can use interfaces instead of requiring packages......just declare interfaces and use the same interface declaration (with the same GUID) both in the application and the dll....just like Delphi IDE does in its Open Tools API (OTA).....

noeska
07-05-2007, 06:36 PM
Sorry to dig up this post but after trying to using a cpp class from an dll (http://www.delphi3000.com/articles/article_2708.asp?SK=) i though by myselves hey this must also be possible with delphi class in an dll. I could not get it to work at first but searching on the forum here i found this thread. The solve seems to be creating a base class that is used as an interface. And inherit the class in the dll from that one. Why is this needed, i do not need it for the cpp one, so why is this needed for the delphi class. I can live with it though, but i am curious for the why and can it be done without like the cpp class to delphi.

L505
02-06-2007, 07:37 AM
See also:

http://www.hu.freepascal.org/lists/fpc-announce/2006-April/000486.html
http://www.freepascal.org/contrib/delete.php3?ID=543