Importing .tbl files

Posted on 2006-05-29
Last Modified: 2012-06-27

I am having trouble importing .tbl files using Delphi 7 and 2005.  

I am creating assemblies using Visual Studio .NET which provides a tool to access them as if they where COM objects.  This tool creates a .tbl file for the assembly.

When I try to import this file using the "Import Type Library" tool of Delphi I always get this message :

"An error occured while referencing a user defined type.  This may be caused by a missing or unregistered type library."

At first I thought that there was a problem with the file itself so I tried to use it with another programming language.  I loaded MS-Access, created a form and used the "Reference" menu to add a reference to the .tbl file.  Once done, could create objects from my class in my assembly and could easily use the HelloWorld method I implemented for testing purpose.  In other words, the tbl seems to work fine.

I tried to import the tbl file with both Delphi 7 and Delphi 2005 without success.

Can anyone help me ?


Question by:qas
    LVL 28

    Expert Comment

    did you regsvr32 that COM dll?

    Author Comment

    Hi :)

    Nope I did not because the dll IS NOT a COM dll, it's a .NET assembly which cannot be registered in the Windows registry but in the Global Assembly Cache.

    Microsoft knows that lots of softwares won't be able to use assemblies for a while so they created a tool to interface assemblies as COM objects through a .tbl file.  This tool (embedded into Visual Studio, it's just a checkbox labeled something like "Register COM Interop") creates the .tbl file along with the .dll.

    And the .tbl actually works!  I could use it with MS-Access with no problem and I am pretty sure that if I had an old VB6 on hand I could use it the same way.

    Any hint ?

    Thanks :)
    LVL 28

    Expert Comment

    could you post that hello world thingie source code so that I can test? I have vs2003 and .net 1.1 and d7/ just never wrote com in vs :)

    Author Comment

    Hi !

    Here is what I do (I am translating from a french version of VS so maybe the wording isn't accurate)

    --------- Creating the assembly ---------
    - New project --> Class library
    - Write this code in Class1.vb:

      Public Class MyTestClass
          Public Sub TestMsg()
          End Sub
      End Class

    - Project Properties --> Configuration properties --> Generate (3rd option) --> Check the "Register COM Interop" Checkbox
    - Build the project

    --------- Testing in Access ---------
    - Start Access
    - Create new database
    - Create new form
    - Drop a button on form
    - Select an event and select the code generator
    - Select Tools --> References...
    - Click "Browse"
    - Select the .tlb file which is located in the BIN directory of the VS project created earlier
    - Make sure the library is checked in the list
    - Click OK to get back to code
    - Insert this code:

      Dim X as New MyTestClass

    - Run the form, get the TEST message

    --------- Testing in Delphi ---------
    - Start Delphi, new application
    - Select Project --> Import type Library
    - Click Add and browse for the .tbl
    - Click Create Unit:  error!


    LVL 28

    Accepted Solution

    hm... I don't have vb installed, only C# and have done what you said and used this code:

    using System;

    namespace ClassLibrary1
          /// <summary>
          /// Summary description for Class1.
          /// </summary>
          public class Class1
                public Class1()
                      // TODO: Add constructor logic here
                public int TestMsg()
                      int i;
                      String s = "";
                      for (i=0;i<10;i++)
                            s = s + i.ToString();
                      if (s.Equals("s"))
                            return 0;// this never happens but who cares anyway :)
                            throw new Exception(s);// didn't find a fast way to display a message so this will have to do

    then imported the tlb and there was no error. however the TestMsg function was not generated. at first I thought there was some optimization and that is why I wrote that weird code.
    PS - I noticed I don't have ms access here. so couldn't test the other way
    LVL 27

    Expert Comment

    If you have a .NET dll file then :-

    C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\regasm DotNet.dll /tlb:DotNet.tlb

    produces a .tbl file which one can import or process to IDL etc....

    Author Comment

    well I feel stupid...

    Whether my Delphi or .NET installation must be corrupted because I tried on another machine and it worked fine on my first attempt.

    By the way, to get the TestMsg function working in Delphi you have to create an Interface and the implement it in the class first (in Visual Studio).  It is the interface that will hold the function's declaration.

    Thanks :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
    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…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    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

    22 Experts available now in Live!

    Get 1:1 Help Now