[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5841
  • Last Modified:

MODI - Microsoft Office Document Imaging OCR with Delphi 2010

Hello fellow developers :)

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

http://www.delphi3000.com/articles/article_4253.asp?SK=

(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
        doc.create(FileName);
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.

WSDeveloper.
0
WSDeveloper
Asked:
WSDeveloper
  • 3
  • 2
1 Solution
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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 delphi3000.com as you've reported.
Attached there's the code.
It's working perfectly here.

The UNIT
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleCtrls, MODI_TLB,comobj;

type
  TForm1 = class(TForm)
    MiDocView1: TMiDocView;
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
Var
  doc :IDocument;
  Img :IImage;
  Layout :ILayout;
begin
  doc := IDispatch(CreateOleObject('MODI.Document')) as IDocument;
  doc.create('c:\OCRTest.tif');  // just put here the filename of an image
  doc.OCR(miLANG_ENGLISH,true,true);
  Img := IDispatch(doc.Images[0]) as IImage;
  Layout := IDispatch(Img.Layout) as ILayout;
  Memo1.Lines.Add(Layout.Text);
  MiDocView1.Document := doc;
  doc.Close(false);
  Img := nil;
  Layout := nil;
end;

end.

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 = {
      00080000D8130000D81300000300000000000300000000000300000000000800
      00000000}
  end
  object Button1: TButton
    Left = 138
    Top = 148
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 1
    OnClick = Button1Click
  end
  object Memo1: TMemo
    Left = 126
    Top = 262
    Width = 185
    Height = 89
    Lines.Strings = (
      'Memo1')
    TabOrder = 2
  end
end

Open in new window

0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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
0
 
WSDeveloperAuthor Commented:
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,

WSDeveloper.
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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!
MODIOCR.exe
0
 
WSDeveloperAuthor Commented:
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,

WSDeveloper.

PS - Happy New Year :)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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