Using ABBYY FineReader Engine in Delphi

This section deals with certain peculiarities of using ABBYY FineReader Engine 12 in Delphi.

Creating the Object Pascal Wrapper Unit

In order to use ABBYY FineReader Engine 12 in Delphi, it is necessary to create the Object Pascal wrapper unit for the type library (the FREngine_TLB.pas file). To generate the wrapper:

  1. Run command prompt (cmd.exe) and go to the folder where the ABBYY FineReader Engine 12 type library (FREngine.tlb) is located.
  2. Run the tlibimp utility with the following parameters:
tlibimp -O- -Cd- -C- -P+ -Pt+ FREngine.tlb
    

This will generate the FREngine_TLB.pas file.

  1. Add FREngine_TLB.pas to your project.

You need to re-generate FREngine_TLB.pas each time you receive an updated version of ABBYY FineReader Engine 12.

Using Engine loaders in Delphi 7

There is also an alternative way of using ABBYY FineReader Engine in Delphi 7, for which you will not need to create the wrapper manually as described above. But this method is only suitable if you load the Engine object in your application using the Engine loaders.

  1. Open your project and choose Project > Import Type Library.
  2. In the dialog that opens, choose ABBYY FineReader Engine 12.5 Type Library in the list. Make sure that Generate Component Wrapper flag is turned on. Click Install.

Note: An error at this stage may indicate that the system environment variable Path does not contain the necessary paths. Modify it to include the path to the mscoree.tlb file (generally it is C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727).

  1. New components appear on the ActiveX tab of the Components palette — InprocLoader and OutprocLoader. You can add one of these components directly onto your form and use it to load the Engine object.

For example, you add the InprocLoader component onto your form. The following code will be added automatically:

uses FREngine_TLB;
type
  TForm1 = class(TForm)
    InprocLoader1: TInprocLoader;
    ...
    private
      { Private declarations }
    public
      { Public declarations }
    end;
    

In your implementation, use the InitializeEngine method of the InprocLoader object to load Engine:

Engine := InprocLoader1.InitializeEngine( 'MyProjectId', LicensePath, LicensePassword, '', '', False );
    

When you no longer need FineReader Engine functionality, unload the Engine using the ExplicitlyUnload method of the loader object.

InprocLoader1.ExplicitlyUnload;
    

Deinitialization of the Engine Object

If not all the objects which were created and used by the application have been deleted before the deinitialization of the Engine object, the "Engine deinitialization failed" exception is thrown. If all the objects have been deleted, the exception may be caused by the garbage collector operation. In Delphi, all objects with the nil value are deleted only after exiting the procedure in which the objects were declared. Therefore, the entire ABBYY FineReader Engine code must be inserted into a separate procedure, and this procedure must be called before the deinitialization of the Engine object.

Note: You can use the StartLogging method of the Engine object to get the list of objects that have not been deleted.

ABBYY FineReader Engine includes a simple Hello sample in Delphi. You can access this sample by selecting Start > Programs > ABBYY FineReader Engine 12 > Installation Folders > Code Samples Folder > Delphi > Hello.

See also

Different Ways to Load the Engine Object

3/24/2023 8:51:52 AM

Usage of Cookies. In order to optimize the website functionality and improve your online experience ABBYY uses cookies. You agree to the usage of cookies when you continue using this site. Further details can be found in our Privacy Notice.