Using a dll from Delphi written in .NET

Posted on 2006-05-03
Last Modified: 2010-04-04
I have a third-party dll that includes a class with properties and methods, that I would like to call from my Delphi-project. I have registered the dll succesfully from the command-prompt.

In VBA I have referenced the tlb-file and made an object of the class TestClass using the following syntax:

Dim a_Class As New TestClass

I want to do the same in Delphi. Any thought on how to do that?


Question by:flycht
    LVL 28

    Accepted Solution

    if the dll is written in .net then you have to used (2005/2006 and I think delphi 8 also has support but I am not sure)
    then you have to import the dll (try from the menu, components, import - I never worked with delphi grater than 7, so I cannot say for sure where the correct menu path is) . when installing the dll, teh delphi wizard should create the tlb (you should be asked for the path to save it)
    then, you just do
    uses blabla_tlb; // or whetever you named the import pas file
    var c:TTestClass;// whatever the name is in the import file

    that is the general way of going. it might differ a little (or more) though :D
    LVL 13

    Assisted Solution

    you mention the "tlb-file", if you have the type library, you can just do

    menu project, import type library, select the file, that will create a Delphi unit that you can use to instantiate the classes or use whatever the type library contains

    Author Comment

    Thanks for your answers. The problem when importing the type library in Delphi 5 is that I get a list of compile errors in mscorlib_TLB where the first one is in line 4515 with the following wording: Type 'Byte' is not yet completely defined. Here is what the code looks like:

    4514  Byte = packed record
    4515    m_value: Byte;
    4516  end;

    Any ideas? Do you think that a newer version will help this problem? Or is there any trick with delphi 5.0 to overcome these errors?

    Best regards

    LVL 28

    Expert Comment

    well, that is because Byte and byte are not the same in .NET (.NET is case sensitive, regular delphi is not)
    and I don't think you can import a .NET library in a non-.NET delphi.
    You could try and rename (using case sensitive search/replace) the Byte in TByte or something that is not yet defined.

    Assisted Solution

    As the BlackTigerX says the simplest way (and might be the only way) is to import as TLB. The problem ur facing might with the datatype that is not compatible to Delphi. Try using different datatype for m_value in .NET.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
    Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now