Painting Pages and Zones (Delphi 6.0)

Take the following steps to add code to the existing project that will let you paint pages and zones:

1.

Start with the program you created in Working with Pages

2.

Add 2 buttons to your form and name them as follows:

 

Name

Caption

 

btnDrawZones

Draw Zones

 

btnDrawPage

Draw Page

3.

Declare the following variables in the public section of Unit1.

bDrawPage: Boolean;
bDrawZones: Boolean;

4.

Update the FormCreate procedure to be as follows:

 procedure TForm1.FormCreate(Sender: TObject); 
begin
 LEADRasterObj:= CreateComObject (CLASS_LEADRaster) as LEADRaster; 
 bDrawPage:= False; 
 bDrawZones:= False; 
end;

5.

Update the btnAddPageClick procedure to be 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 ); 

 bDrawPage:= False; 
 LEADRasterDocument1.ActivePageIndex:= 0; 
 bDrawPage:= True; 

   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;

 

6.

Code the btnDrawZones button's click procedure as follows:

procedure TForm1.btnDrawZonesClick(Sender: TObject); 
begin
 bDrawZones:= Not bDrawZones; 
end;

 

7.

Code the btnDrawPage button's click procedure as follows:

procedure TForm1.btnDrawPageClick(Sender: TObject); 
begin
   if ( bDrawPage = True ) then
   begin
    LEADRasterDocument1.EnableShowZones:= bDrawZones; 
    LEADRasterDocument1.DrawPersistence:= False; 
    LEADRasterDocument1.DrawPage ( Nil, Self.Canvas.Handle, 0 ); 
   end; 
end;

 

8.

Run your program to test it.