This component was originally written as a pascal unit by Shalonkin ALex (or Alex Shalonkin) and worked fairly well. Its purpose was to print a DBGrid and have it look like a nice report. One can customize the title, the first page header color, page numbering, font and etc. It originally had a one page print preview which could be displayed in a TImage. Since this preview never "looked right" it was  removed. The original code, (with some modifications in an attempt to view a good looking preview), for the preview is still in the code, just REMed out.

Many properties were added and the events made available just in case.

This component is freeware, as was the original. USE IT AT YOUR OWN RISK. I guarantee nothing! Modify it if you wish but I would appreciate any changes and upgrades that are made be emailed to me. I learn a lot through other's code!

Should compile and install just fine for any version of Delphi, at least from D3 to D6. Tested and written under Delphi 5, however.

I want to thank Alexander Rodygin for translating the original Russian language text into English!

Installation

Installation is easy. Place the dcr and the pas file in your component directory and install a new component into your Delphi Users library, or where ever you desire.

Properties

BottomMargin     Adjust for an approprioate bottom margin. Default is 160, about 3/8 inch.
DBGrid		 Set this to the DBGrid you want to print, i.we. dbGrid1.
HeaderColor	 This affects the entire header including the report title and page number.
LeftMarginh	 Adjust for an appropriate left margin. The default is 240, about 1/2 inch.
LogPanel	 Set this to a panel for logging/text progress of the component.
PageNumFontName	 Set this to the font name for the page number. I.E., Times New ROman, default.
PageNumFontSize	 Set this to the font size that you want the page number to be. Default is 8. 
PrintDialog	 True or False to have a printer dialog appear. Defrault is false.
PrintOrientation Landscape or portrait. Default is poPortrait.
PrintPageNum	 True or False to print a page number. Default is true.
PrintProgressBar Set to a TProgressBar to visually show component progress. (Not that good).
RightMargin	 Set for an appropriate right margin. Default is 60. The right margin varies due to grid width.
RowNumber	 True or False to number the rows in the first column.
TopMargin	 Set for an appropriate top margin. Default is 0 which places it about 3/8 from the top.

Events

OnLogChangeEvent This is fired everytime the log text changes for the panel.
OnNextPageEvent	 This is fired everytime the component calculates a new page.


*****************************************************************
		
Usage

Place component on your form, set a grid and other properties. In your button event handler, the following will print a nice looking grid report.


procedure TForm1.BitBtn1Click(Sender: TObject);
var PrintReport:TPrintReport;
begin
  PrintGrid.Title.Add(0,'Employee Grid ', 12, [fsBold], taLeftJustify);
  PrintGrid.Title.Add(0,'Printed on' + DateToStr(Date), 8, [], taRightJustify);
  PrintGrid.Bottom.Add(0,'End of report',8,[fsBold],taLeftJustify);
  PrintGrid.Bottom.Add(0,'Finsihed on ' + DateToStr(Date), 8, [], taRightJustify);
  PrintGrid.Print;
end;

******************************************************************

Instead of making static properties in the design time component for header titles and last page footer information, it was thought that individually setting titles and bottom footers as above was simpler and gave more control over the component and your printed report, as did the original unit.

         .Bottom.
PrintGrid.Title.Add(Position:Integer, Title:String, FontSize:Integer, FontStyle:TFontStyle, Alignment:TAlignemnt):Integer

Play around with the Position number as this will place the Title/Bottom (last page footer) in a different position on your printed form. A O (zero) will place it, the title or bottom (last page footer), at the set left margin. 

Enjoy! 

John Jarrett
Jarrett Consulting and IT Services
formerly, Computer Engineering Services
johnj@jcits.d2g.com
www.jcits.d2g.com

Original Author:
Autor Shalonkin Alex
e-mail: alex@vita-samara.ru
