Recent

Author Topic: how to read TOTALPAGES value from Object Pascal  (Read 3544 times)

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
how to read TOTALPAGES value from Object Pascal
« on: July 06, 2015, 05:40:01 pm »
I am printing a report with a dynamic number of columns. I'm not using CrossTab (or CrossData) reporting. Anyway, my report works fine, but the page count and total pages in the footer are wrong. I introduced a OffsetPage variable which I add to the page number and total pages, but that has problems with reports where the rows are large and prints on multiple pages.

So I need to know between every run, what the total number of pages were of the previous report, so I can adjust my OffsetPage variable correctly. Does anybody know how I can read back the total number of pages after a report was created, but before the print-preview window is freed?

I tried the following, and both methods don't work.

Code: [Select]
  PreviewForm.ShowModal;
  if FRPrint.Values.FindVariable('TOTALPAGES') <> nil then
    ShowMessage(FRPrint.Values.FindVariable('TOTALPAGES').Field);

The above code never runs because the IF statement is never true.

Code: [Select]
  PreviewForm.ShowModal;
  ShowMessage(IntToStr(FRPrint.Pages.Count));

This always returns 1, even if my report prints 2 or more pages.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

paweld

  • Hero Member
  • *****
  • Posts: 970
Re: how to read TOTALPAGES value from Object Pascal
« Reply #1 on: July 06, 2015, 08:56:53 pm »
in reports desinger: 'File' > 'Report options ...'  select "Two-pass report" checkbox on the first page
Best regards / Pozdrawiam
paweld

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: how to read TOTALPAGES value from Object Pascal
« Reply #2 on: July 06, 2015, 09:12:42 pm »
Thank you Paweld, but 2-pass is not the problem. In a simple report my page numbers and total page count works fine. But if my report has more column than can fit on a page, I run the report multiple times automatically. In these multiples, I need to fix up the page numbering by using a PageOffset variable.

eg, in the footer I wanted to have:
Code: [Select]
  [PageOffset+Page#] / [PageOffset+TotalPages]

but that didn't work as expected.

So with large number of column data, the report can run 2 or more times, but I want to keep the page numbers in sequence. I need to keep track of the number or pages, so I can set the PageOffset variable to the correct value on the next print.

I've solved the problem if I remove the [TotalPages] variable from the report. Then I can simply increment a variable in the Report.OnBeginPage. But as you mentioned, if you use the TotalPages variable, you need to enable 2-pass reporting, which means the OnBeginPage event fires twice as many times as it should. Thus screwing up the PageOffset value.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

paweld

  • Hero Member
  • *****
  • Posts: 970
Re: how to read TOTALPAGES value from Object Pascal
« Reply #3 on: July 07, 2015, 10:13:36 am »
Do you can attach a example project?
Best regards / Pozdrawiam
paweld

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: how to read TOTALPAGES value from Object Pascal
« Reply #4 on: July 07, 2015, 10:38:49 am »
Unfortunately I can't with the original project because it is commercial software. But I'll try and put a small sample together that reproduces the issue.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

 

TinyPortal © 2005-2018