【问题标题】:Delphi Quick Reports - Total PagesDelphi 快速报告 - 总页数
【发布时间】:2010-09-01 10:04:05
【问题描述】:

我在我的应用程序中使用 QuickReports,并希望在页脚中添加“Page x of x”。最好的方法是什么?

【问题讨论】:

    标签: delphi quickreports


    【解决方案1】:
    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;
    

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

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

    procedure TForm2.QRLabel1Print(sender: TObject; var Value: string);
    begin
      Value := 'Page: ' + IntToStr(QuickRep1.QRPrinter.PageNumber) + ' of ' + IntToStr(FTotalPages);
    end;
    

    【讨论】:

      【解决方案2】:

      首先准备好文档,让系统自己知道会产生多少页。您可以使用一个系统变量(手头没有 QR 可以告诉您确切的名称)。

      例如:

      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;
      

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-03-28
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多