Using a dll from Delphi written in .NET

Posted on 2006-05-03
Medium Priority
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

2266180 earned 672 total points
ID: 16594694
if the dll is written in .net then you have to used delphi.net (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

BlackTigerX earned 664 total points
ID: 16600016
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

ID: 16612618
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

ID: 16612708
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

srisha earned 664 total points
ID: 16629642
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.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month17 days, 2 hours left to enroll

864 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