Search code examples
delphidelphi-2007richedittypelib

Delphi how to import type library for new ITextRange2 type interfaces?


I'm using a Microsoft Text Object Model type library in Delphi for using some features of the Microsoft RichEdit control. That type library was included in a freeware component and worked very well over the years. For example, here is an ITextDocument interface that it shows:

  ITextDocument = interface(IDispatch)
    ['{8CC497C0-A1DF-11CE-8098-00AA0047BE5D}']
    function Get_Name: WideString; safecall;
    function Get_Selection: ITextSelection; safecall;
    function Get_StoryCount: Integer; safecall;
  ...

I don't know how that was created. Now I want to update it for new interfaces published for RichEdit in Windows 8 (MSFTEDIT.DLL). For example, there is a Range2 method in ITextDocument2 and a new ITextRange2 interface according to MSDN. Is there some way I can use Delphi's Import Type Library feature to make up the definitions of the new interfaces?

Update: I figured out how to generate that unit. In Delphi, click on Import Component and then select "tom" from the registered services. This creates a unit exactly like that. Now the problem is, in order to get the new "tom" interface from Windows 8, it will be too much if I'm required to install Delphi on it. There must be a simpler way. Somehow I have to generate a TLIB on Win 8 and then import it in my Delphi on Windows 7. Anyone knows how to generate a TLIB on Windows 8 for that msftedit.dll or tom interface?

Another find: If I open the msftedit.dll in Delphi by opening as a tlib, it shows all the interfaces. There is an export button too but that does not work when clicked. Nothing happens. I searched for Type Lib Explorer help in the help file and on the web but didn't find anything on why that export button does not work.


Solution

  • You can use the command line utility tlibimp to import the type library on Windows 8. You can find tlibimp.exe in the bin directory of your Delphi installation. Since you want to avoid installing Delphi on your Windows 8 machine, transfer tlibimp.exe to the Windows 8 machine. And then run this command:

    tlibimp -P msftedit.dll
    

    This will generate the Pascal type library import file that you need.