Results 1 to 6 of 6

Thread: Classes vs Dll's

  1. #1
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Classes vs Dll's

    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:
    [pascal]
    TDLL_GUIControl = class
    private
    public
    RegisterSomthingFromApp;
    DoSomething1;
    DoSomething2;
    end;
    [/pascal]

    Whitin MyApp
    [pascal]
    TMyApp_GUIControl = class(TDLL_GUIControl)
    private
    public
    RegisterSomthingFromApp;
    DoSomething1; override; // override stuff?
    DoSomething2;
    MyOwnDoSomething;
    end;
    [/pascal]

    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.
    NecroSOFT - End of line -

  2. #2

    Classes vs Dll's

    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
    [pascal]
    type TTestClass = class
    procedure DoStuff; virtual; abstract;
    end;
    [/pascal]


    The DLL
    [pascal]
    type TTestClassImp = class(TTestClass)
    procedure DoStuff; override;
    end;


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

    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
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  3. #3
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Classes vs Dll's

    Thanx... will write a test program when I get home.
    NecroSOFT - End of line -

  4. #4

    Classes vs Dll's

    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).....

  5. #5

    Classes vs Dll's

    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.
    http://3das.noeska.com - create adventure games without programming

  6. #6

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •