如何在报表的页脚显示"共几页"(50分)

  • 主题发起人 主题发起人 y313
  • 开始时间 开始时间
Y

y313

Unregistered / Unconfirmed
GUEST, unregistred user!
我用Delphi4编一个报表程序,用quickreport倥件,只能显示"第 页',不能显示"共 页"
我如何做?
 
在打印或打印预览前如何获取报表页数

   我们有时需要在打印前获取报表的打印页数, 比如我们需要在页眉或页脚中打印"共 xx 页 第 xx 页",那如何实现呢? QuickRep生成Report之前,我们是无法得知报表页数的,而QuickReport是在打印或打印预览时才生成报表,换言之我们只有在 打印或打印预览前先将报表生成一次才能获取打印页数.生成报表的方法是 Prepare。参考以下的例子:
...
var nPageCount:integer;
begin

  {...}
   QuickRep1.Prepare;
   nPageCount:=QuickRep1.QRPrinter.PageCount;
   QuickRep1.QRPrinter.Free;
   QuickRep1.QRPrinter:=nil;
   {在此修改QuickRep1,实现在页眉或页脚中打印"共 xx 页 第 xx 页" ... }
   QuickRep1.PreView;
   {...}
End;
 
To:程云:
按照你的方法,我无法实现,我得到的是0页,为什么?
 
Q1:
How can I determine the number of pages in my report before I preview or print it?
A1:
If you call the report's Prepare method, it will generate the report without
printing or previewing it. After Prepare has finished, the pagecount will be
in the report's qrprinter.pagecount property. Please refer to the manual topic
on Prepare for more information.
Example:
QuickRep1.Prepare;
QuickRep1.ReportTitle := 'This report has ' +
IntToStr(QuickRep1.QRPrinter.PageCount) + ' pages';
QuickRep1.QRPrinter.Free;
QuickRep1.QRPrinter := nil;
QuickRep1.Preview;
==========================================
Q:
We've a problem with QRPrinter.PageCount. We've created our own Previewform
and when we call QRPrinter.PageCount we always get 0. What's wrong??
A:
You need to specify the preview's qrprinter, otherwise the global qrprinter will
be used. Also, the total page count is not known when the preview is first shown,
you must use the preview's OnPageAvailable to update the page count as each page
is rendered.
Example:
procedure TfrmPreview.QRPreviewPageAvailable(Sender: TObject;
PageNum: Integer);
begin
if PageNum = 1 then
Caption := QRPreview.QRPrinter.Title + ' - 1 page'
else
Caption := QRPreview.QRPrinter.Title + ' - ' + IntToStr(PageNum) + ' pages';
case QRPreview.QRPrinter.Status of
mpReady: Caption := Caption + ' READY';
mpBusy: Caption := Caption + ' BUSY';
mpFinished: Caption := Caption + ' FINISHED';
end;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
var
Page:integer;
begin
form2.QuickRep1.Prepare;
Page:=form2.QuickRep1.PageNumber;
form2.QRLabel4.caption:=inttostr(Page);
//QRLabel4 共计页
form2.QuickRep1.Preview;
end;
 
用记录数,当前页,总记录数计算
 
应该就是这些方法了~~~
 
后退
顶部