开发者

Delphi Quick Reports - Total Pages

开发者 https://www.devze.com 2023-01-14 15:24 出处:网络
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?procedure TForm1.Button1Click(Sender: TObject);

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?


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;


First prepare the document, so the system itselfs know how many pages will produce. There's a system variable you can use (no QR at hand to tell you the exact name).

For example:

procedure TForm1.Click(Sender: TObject);
begin
  //this actually run the report in memory to 
  //calculate things like total page count
  Report1.Prepare;  
  Report1.Print;  //or PreviewModal;
end;


A solution is to count the number of pages during preview so when you send it to the printer you can place it in the footer.

0

精彩评论

暂无评论...
验证码 换一张
取 消