Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi Quick Reports - Total Pages

I'm using QuickReports within my application and would like to have "Page x of x" within the footer. What's the best way to do this?

like image 637
PDM Avatar asked Apr 10 '26 12:04

PDM


1 Answers

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.QuickRep1.Prepare;
  Form2.QuickRep1.FTotalPages := Form2.QuickRep1.QRPRinter.PageCount;
  Form2.QuickRep1.QRPrinter.Free;
  Form2.QuickRep1.QuickRep1.QRPrinter := nil;
  Form2.QuickRep1.PreviewModal; // or .Print
end;

FTotalPages is declared in Form2 that holds the TQuickRep component.

public
    { Public declarations }
    FTotalPages: Integer;

Note that the QRPrinter object must be freed after Prepare and before PreviewModal (or .Print) else you will get a memory leak.

In Form2, on the Quickreport1, place a QRLabel, and implement it's onPrint event handler

procedure TForm2.QRLabel1Print(sender: TObject; var Value: string);
begin
  Value := 'Page: ' + IntToStr(QuickRep1.QRPrinter.PageNumber) + ' of ' + IntToStr(FTotalPages);
end;
like image 173
Freddie bell Avatar answered Apr 12 '26 10:04

Freddie bell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!