Recent

Author Topic: [Solved] GridPrn page break issue  (Read 1329 times)

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 632
    • Double Dummy Solver - free download
[Solved] GridPrn page break issue
« on: January 08, 2024, 05:38:27 pm »
I'm having a problem with the GridPrn component. I believe the user has the ability to insert a page break where desired by inserting "$Page" into column 0 of the desired line. This would seem to be handled on line 1003 of GridPrn.pas
Code: Pascal  [Select][+][-]
  1.     if (totalHeight > FPageRect.Bottom) or (GetCellText(0,row)='$Page') then
GetCellText does not return the string value in that cell. Anyone have an idea how to get the desired string value?
« Last Edit: January 09, 2024, 01:04:07 am by bobonwhidbey »
Lazarus 4.8 FPC 3.2.2 x86_64-win64-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 13628
Re: GridPrn page break issue
« Reply #1 on: January 08, 2024, 05:48:59 pm »
I'm having a problem with the GridPrn component.
You mean the GridPrinter component?

This component was not designed to allow user-defined page-breaks. The symbol '$Page' is just a place-holder for the current page number to be displayed in the header/footer.

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 632
    • Double Dummy Solver - free download
Re: GridPrn page break issue
« Reply #2 on: January 08, 2024, 11:00:35 pm »
Yes, TGridPrinter in the GridPrinterPkg.  I guess I was just hoping that '$Page' had a meaning that would fit my needs. I can see I was dreaming :[  I want to be able to control where page breaks occur - especially to handle different page heights; e.g. A4 and "letter size" which is 8.5 inches x 11 inches.

Since GetCellText(0,row) doesn't seem to pick up what's written in that cell, do you know how I can read that cell so I can roll my own version of TGridPrinter? My underlying grid is a TDrawGrid.
« Last Edit: January 08, 2024, 11:17:58 pm by bobonwhidbey »
Lazarus 4.8 FPC 3.2.2 x86_64-win64-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 13628
Re: GridPrn page break issue
« Reply #3 on: January 09, 2024, 12:23:43 am »
I just committed a modified version of the GridPrinter to CCR (https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/gridprinter/) which has a new event OnManualPageBreak. The grid has the col/row index, as well as a flag indicating whether that index refers to a column or to a row, as parameters. You must set the parameter NewPage to true when you want to introduce a pagebreak at the specified column or row index. The following event handler, for example, results in a manual pagebreak after every 10 rows:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.GridPrinter1ManualPageBreak(Sender: TObject;
  2.   AGrid: TCustomGrid; IsCol: Boolean; AColRowIndex: Integer;
  3.   var NewPage: Boolean);
  4. begin
  5.   if not IsCol and (AColRowIndex mod 10 = 0) then
  6.     NewPage := true;
  7. end;

If you want to make the page breaks depend on the contents of the cells you have also the underlying grid as a parameter.

GetCellText should return the cell text. When it's not working for you the reason may be in the TDrawGrid that you are using since a TDrawGrid does not store any strings.
     

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 632
    • Double Dummy Solver - free download
Re: GridPrn page break issue
« Reply #4 on: January 09, 2024, 01:03:48 am »
Works PERFECTLY for me. Thanks a million WP.
Lazarus 4.8 FPC 3.2.2 x86_64-win64-win32/win64

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 632
    • Double Dummy Solver - free download
Re: [Solved] GridPrn page break issue
« Reply #5 on: March 09, 2025, 02:07:00 am »
The version of the GridPrinter component in the Online Package Manager doesn't have OnManualPageBreak and thus doesn't work while the link WP provided above works great.
Lazarus 4.8 FPC 3.2.2 x86_64-win64-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 13628
Re: [Solved] GridPrn page break issue
« Reply #6 on: March 09, 2025, 03:00:54 pm »
Updated OPM.

 

TinyPortal © 2005-2018