真是怪问题!(100分)

  • 主题发起人 主题发起人 oicu
  • 开始时间 开始时间
O

oicu

Unregistered / Unconfirmed
GUEST, unregistred user!
这样!俺做的一个报表,要求在页脚能显示:“第X页 共X页” 其中为了显示“共X页”,用了一下语句:

Procedure TForm1.BitBtn6Click(Sender:TObject);
begin
Form2.QuickRep1.Prepare;
try
Form2.QRLabel8.Caption:=IntToStr(Form2.QuickRep1.QRPrinter.PageCount);
//上句用于显示总页数
finally
Form2.QuickRep1.QRPrinter.Free;
Form2.QuickRep1.QRPrinter:=nil;
end;
Form2.QuickRep1.Preview;
Form2.Free;
Form2:=nil;
end;

但奇怪的是无论怎么运行,总页数都只显示0! 不知怎么搞!请问,,总页数如何显示?!
 
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;
 
还是不太懂,
--英文!
 
QuickRep1.Prepare;
Caption := IntToStr(QuickRep1.Printer.PageCount)
 
下面也可以的呀。。。
QuickRep1.Prepare;
Caption := IntToStr(QuickRep1.QRPrinter.PageCount)
 
嗨!看出毛病来了。你使用下面这句得到的数值是对的,但是你再次调用Preview的时候这个数值再次被刷新了,所以就错了。
将你Prepare以后得到的PageCount保存到一个全局变量中,然后在你的BeforePrint里面直接给QrLabel赋值就可以了。
Form2.QRLabel8.Caption:=IntToStr(Form2.QuickRep1.QRPrinter.PageCount);
 
I often use English answer questions.Why don't you read carefully?
 
后退
顶部