MODI - Microsoft Office Document Imaging OCR with Delphi 2010

Posted on 2009-12-26
Last Modified: 2012-05-08
Hello fellow developers :)

We are trying to write an OCR module, using the Microsoft Office Document Imaging (MODI), as per the following article:

(There are number of other sites with same or similar code - I am assuming they all came from this one source).

Unfortunatelly, we are not able to make this work. The second line
generates an error message "Class Not Registered".

We have tried number of different OS Versions (Win XP and 7) / Delphi versions (D7, D2007 and D2010)/ MS Office Versions (2003 and 2007), but no luck. The same error is reproducible every single time.

We have found few articles on the web describing other developers having similar issues, but have not seen a concrete solution to this problem.

Can someone advise if there are any known issues with the more recent versions of MODI, or if there is another way to make this work?

Ideally, I would like someone to provide a sample / instructions on how to get this working reliably on D2010.

Thank you for your help.

Question by:WSDeveloper
    LVL 22

    Expert Comment

    by:Ferruccio Accalai
    I've tried to import the ActiveX into my Delphi2010 but cannot found a way to make it work (file recognizing errors).

    So then, I've changed the approach and finally I got it working.

    OS: Windows Vista Business Sp2
    Delphi 2010 Professional
    Microsoft Office 2007

    Here's a step by step of what I've done

    From Delphi Ide
    Component -> Import Component
    Here I've selected Import Type Library (as Import ActiveX gave me lot of errors before)
    Choosed from the list "Microsoft Office Document Imaging 12.0 Type Library" v. c.0
    Choosed "ActiveX" as Palette Page
    Choosed "Create new Package" giving it a friendly name.

    Now, if you try to compile the package you get an error saying that TImage is already present in another package.
    In fact the imported unit  MODI_TLB.pas contains a class TImage that is already present in delphi, so my work around was to replace any "TImage" found in code with "TMyImage".
    After this replacing I've compiled and installed the package, and got every component of this package in the Activex palette.
    Well, at this point I've created first of all a .tif file called OCRTest.tif (but had succes with a jpg also) containing some text and saved it to C:\

    Then I've created a project using the same code from as you've reported.
    Attached there's the code.
    It's working perfectly here.

    The UNIT
    unit Unit1;
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, OleCtrls, MODI_TLB,comobj;
      TForm1 = class(TForm)
        MiDocView1: TMiDocView;
        Button1: TButton;
        Memo1: TMemo;
        procedure Button1Click(Sender: TObject);
        { Private declarations }
        { Public declarations }
      Form1: TForm1;
    {$R *.dfm}
    procedure TForm1.Button1Click(Sender: TObject);
      doc :IDocument;
      Img :IImage;
      Layout :ILayout;
      doc := IDispatch(CreateOleObject('MODI.Document')) as IDocument;
      doc.create('c:\OCRTest.tif');  // just put here the filename of an image
      Img := IDispatch(doc.Images[0]) as IImage;
      Layout := IDispatch(Img.Layout) as ILayout;
      MiDocView1.Document := doc;
      Img := nil;
      Layout := nil;
    The FORM
    object Form1: TForm1
      Left = 196
      Top = 92
      Caption = 'Form1'
      ClientHeight = 444
      ClientWidth = 680
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = []
      OldCreateOrder = False
      PixelsPerInch = 96
      TextHeight = 13
      object MiDocView1: TMiDocView
        Left = 404
        Top = 116
        Width = 192
        Height = 192
        TabOrder = 0
        ControlData = {
      object Button1: TButton
        Left = 138
        Top = 148
        Width = 75
        Height = 25
        Caption = 'Button1'
        TabOrder = 1
        OnClick = Button1Click
      object Memo1: TMemo
        Left = 126
        Top = 262
        Width = 185
        Height = 89
        Lines.Strings = (
        TabOrder = 2

    Open in new window

    LVL 22

    Expert Comment

    by:Ferruccio Accalai
    Just one thing in addition (important, yes) that I forgot to say before in the step-by-step.
    To make it work I needed to add to the project the unit MODI_TLB.pas because for some strange reasons, even if it was in the Library Path ($BDS/Imports), the compiler couldn't find it.
    After adding it to the project units everything works fine.

    Hope all this can help you

    Author Comment

    Hi Ferruccio68,

    Thank you for your prompt response. You are right - there are some pitfalls in the installation of the component itself... But, I have followed your instructions exactly as you mentioned...

    Imported Type Library, saved it to a new package. The system then came up with the different components, such as TDocument, TLayout, TImages etc...

    Then, I have created a new application, using the above code, and it runs, but it crashes on the second line (doc.create...) with "Class Not Registered"...

    Since you have said it works on your PC, we have tried number of different computers, with Office 2003 and 2007, running on XP and Windows 7, using Delphi/RAD studio 2010, but always get the same result...

    It is unbelievable that the same thing works on your end but does not work on any of our computers (PCs, Laptops, WMs etc)...

    Could I please ask you to post your EXE on here, so that I can download it, and try your application - to see if it will give us the same result, or if it will actually work...

    We have nothing else on our computers, pretty much standard installs etc - we have even tried on a blank WM where we installed just Office 2007 and nothing else - but it still does not work...

    One other thing I would like to ask - do you have any other development studios on your system. Do you have Visual Studio etc? I am just wondering if it needs a separate component or library or something, which could be installed as part of another package...

    Thanks again for you help, and Happy New Year to you :)

    Best Regards,

    LVL 22

    Accepted Solution

    It seems that you have another package already installed as you said that it find some components alredy installed like TDocument etc. (maybe any DOM Parser?)

    About Visual Studio the only thing here in my machine is the standard Visual Studio 2005 Remote Debugger, but I don't think that it could interact with the succesful compiling of the package.

    BTW I've attached the exe that is working here. Try it.
    If it works I'll pass you my .dpk and .pas files (maybe after tomorrow, 2010 is coming :D)

    Best wishes and Happy New Year you too!

    Author Comment

    Hi Ferruccio68,

    We have ran your program, and it did not work on first attempt either... We have re-installed the MS Office Imaging Components, and then it worked just fine...

    Only explanation I can come up was that when we have installed the MS Office first, we always do it in default install mode, not full / complete... So it was set up to be installed on first use... We have then changed using add / remove components to be installed on the hard drive - and it did not work...But the type library was there, and we were able to link it to Delphi etc...

    Now with your program, we have installed MSOffice 2007 on a new PC, and did a full install, so that it has all the components there to start with, and it now worked... We have then tried our program, and it worked also...

    Finally, whilst doing some research on the web, I found out that MODI will be changed in Microsoft Office 2010. It will no longer be a stand alone component, but it will be tightly integrated into MS Word... (There is bunch of articles on the web on this issue) So for anyone using it like this with Delphi - be aware that there will be changes in Office 2010...

    Thank you for your help regarding this issue.

    Best Regards,


    PS - Happy New Year :)

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
    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…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    731 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

    18 Experts available now in Live!

    Get 1:1 Help Now