• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1087
  • Last Modified:

Using a dll from Delphi written in .NET

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?


3 Solutions
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
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
flychtAuthor Commented:
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

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.
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now