Delphi 快速报告 - 总页数

发布于 2024-09-16 11:47:01 字数 62 浏览 2 评论 0原文

我在应用程序中使用 QuickReports,并希望在页脚中包含“第 x 页,共 x 页”。最好的方法是什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

千秋岁 2024-09-23 11:47:01
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 在保存 TQuickRep 组件的 Form2 中声明。

public
    { Public declarations }
    FTotalPages: Integer;

请注意,必须在Prepare之后和PreviewModal(或.Print)之前释放QRPrinter对象,否则您将遇到内存泄漏。

在 Form2 的 Quickreport1 上,放置一个 QRLabel,并实现它的 onPrint 事件处理程序

procedure TForm2.QRLabel1Print(sender: TObject; var Value: string);
begin
  Value := 'Page: ' + IntToStr(QuickRep1.QRPrinter.PageNumber) + ' of ' + IntToStr(FTotalPages);
end;
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;
顾北清歌寒 2024-09-23 11:47:01

首先准备文档,以便系统本身知道将生成多少页。您可以使用一个系统变量(手头没有二维码可以告诉您确切的名称)。

例如:

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;

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;
悍妇囚夫 2024-09-23 11:47:01

解决方案是在预览期间计算页数,以便在将其发送到打印机时可以将其放置在页脚中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文