Working with Pages (Delphi 6.0)
Take the following steps to create and run a program that shows how to work with pages in an OCR document. Remember, the purpose of the tutorials is to provide you with a quick and easy way to generate an OCR program.
1. |
Start Delphi 6.0. |
2. |
If you didn’t import LEAD Raster Object before, import it as follows: |
|
On the Project pull-down menu, use the Import Type library… and select the LEAD Raster object library (14.5). Press install, and then compile and install the package dclusr.dpk. |
3 |
If you didn’t import LEAD Raster Process Object before, import it as follows: |
|
On the Project pull-down menu, use the Import Type library… and select the LEAD Raster Process object library (14.5). Press install, and then compile and install the package dclusr.dpk. |
4. |
If you didn’t import LEAD Raster OCR Document Object before, import it as follows: |
|
On the Project pull-down menu, use the Import Type library… and select the LEAD Raster OCR Document object library (14.5). Press install, and then compile and install the package dclusr.dpk. |
5. |
If you didn’t import LEAD Raster IO Object before, import it as follows: |
|
On the Project pull-down menu, use the Import Type library… and select the LEAD Raster IO object library (14.5). Press install, and then compile and install the package dclusr.dpk. |
6. |
From the ActiveX tab, Select and Add LEADRasterIO, LEADRasterProcess, and OCR LEADRasterDocument controls to your form. |
7. |
At the beginning of the Unit1 file, add ‘LTRASTERLib_TLB’, ‘ActiveX’ and ‘ComObj’ units to the uses section. |
8. |
Declare the following variable in the public section of Unit1. |
LEADRasterObj: LEADRaster;
9. |
Add 6 buttons to your form and name them as follows: |
|
|
Name |
Caption |
|
btnStartUp |
Start Up |
|
btnShutDown |
Shut Down |
|
btnAddPage |
Add Page |
|
btnRemovePage |
Remove Page |
|
btnSetLanguages |
Set Languages |
|
btnFlipPage |
Flip Page |
10. |
Code the main form's Create procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code. |
procedure TForm1.FormCreate(Sender: TObject);
begin
LEADRasterObj:= CreateComObject (CLASS_LEADRaster) as LEADRaster;
if ( LEADRasterObj = Nil ) then
begin
ShowMessage ( 'Error Creating LEAD Raster Object' );
Application.Terminate ( );
end;
end;
11. |
Code the btnStartUp button's click procedure as follows: |
procedure TForm1.btnStartUpClick(Sender: TObject);
begin
//notice the OCR key is a test key.
LEADRasterObj.UnlockSupport ( L_SUPPORT_OCR, 'TestKey' );
LEADRasterDocument1.StartUp ( );
end;
12. |
Code the btnShutDown button's click procedure as follows: |
procedure TForm1.btnShutDownClick(Sender: TObject);
begin
LEADRasterDocument1.ShutDown ( );
end;
13. |
Code the btnAddPage button's click procedure as follows: |
procedure TForm1.btnAddPageClick(Sender: TObject);
var
nRet: Integer;
nPageNumber: Integer;
begin
nPageNumber:= 0;
nRet:= LEADRasterIO1.Load ( LEADRasterObj, 'c:\OCRTEST.gif', 0, 0, 1 );
if ( nRet <> 0 ) then
ShowMessage ( 'Error loading file' );
nRet:= LEADRasterDocument1.AddPage ( LEADRasterObj, nPageNumber );
if ( nRet = 0 ) then
begin
ShowMessage ( 'Page Width = ' + IntToStr(LEADRasterDocument1.PageWidth [nPageNumber]) + Chr(13) +
'Page Height = ' + IntToStr(LEADRasterDocument1.PageHeight [nPageNumber]) + Chr(13) +
'Page Bits Per Pixel = ' + IntToStr(LEADRasterDocument1.PageBitsPerPixel [nPageNumber]));
end
else
ShowMessage ( 'The engine could not add a new page to the Document' );
end;
14. |
Code the btnRemovePage button's click procedure as follows: |
procedure TForm1.btnRemovePageClick(Sender: TObject);
var
i: Integer;
nRet: Integer;
nPageCount: Integer;
begin
nPageCount:= LEADRasterDocument1.PageCount;
For i:= 0 to nPageCount - 1 do
begin
LEADRasterDocument1.CleanupPages(True);
nRet:= LEADRasterDocument1.RemovePage (i);
if ( nRet = 0 ) then
ShowMessage ( 'The page # ' + IntToStr(i) + 'is removed successfully' );
end;
end;
15. |
Code the btnSetLanguages button's click procedure as follows: |
procedure TForm1.btnSetLanguagesClick(Sender: TObject);
var
nRet: Integer;
begin
LEADRasterDocument1.ActiveLanguagesCount:= 1;
LEADRasterDocument1.ActiveLanguage [0]:= LANGID_ENGLISH;
nRet:= LEADRasterDocument1.SelectLanguages ();
if ( nRet <> 0 ) Then
ShowMessage ( 'Error ' + IntToStr(nRet) + 'Setting English as default language' )
else
ShowMessage ( 'English is Set as the active language' );
end;
16. |
Code the btnFlipPage button's click procedure as follows: |
procedure TForm1.btnFlipPageClick(Sender: TObject);
var
nRet: Integer;
begin
LEADRasterDocument1.ExportPage ( LEADRasterObj, 0 );
LEADRasterProcess1.Flip ( LEADRasterObj );
nRet:= LEADRasterDocument1.UpdatePage ( LEADRasterObj, 0 );
if ( nRet = 0 ) then
ShowMessage ( 'The specified page is updated successfuly' )
else
ShowMessage ( 'Error ' + IntToStr(nRet) + ' in updating page bitmap for page # 0' );
LEADRasterDocument1.ActivePageIndex:= 0;
end;
17. |
Run your program to test it. |
18. |
Save the project to use as a starting point for other tasks in this tutorial. |