Quickreport万能打印程序的详细介绍
作程序经常使用报表打印,使用delphi编程最长用的是使用quickreport做报表打印,rave是在delphi7中才出现的,我用quickreport做了一个万能打印程序,由于时间紧迫,没有时间优化和美化,欢迎网友修改。
他的基本思想是:动态的取dataset中的列,动态的生成报表,程序如下:
unit unit_QReport_lxr;
interface
uses Windows, SysUtils, Messages, Classes, Graphics, Controls,
StdCtrls, ExtCtrls, Forms, QuickRpt, QRCtrls, DB, ADODB,Dialogs;
type
TQReport_lxr = class(TQuickRep)
DetailBand1: TQRBand;
TitleBand1: TQRBand;
bb_title: TQRLabel;
ColumnHeaderBand1: TQRBand;
private
public
function bb_prepare(objAdoQuery:TDataSet;haveFirstCol:boolean):boolean;
end;
var
QReport_lxr: TQReport_lxr;
implementation
{$R *.DFM}
function TQReport_lxr.bb_prepare(objAdoQuery:TDataSet;haveFirstCol:boolean):boolean;
file://haveFirstCol:boolean;是否打印dataset中的第一列,true打印,false 不打印
var
la:TQRLabel ;
te:TQRDBText;
row_la:integer;
row_te:integer;
re_width:integer;
left_bj:integer;
i:integer;
j:integer;
m:integer;
hafn:integer;
begin
if (objAdoQuery.Fields.Count<=0)then
begin
messagedlg('请您先做查询,再打印报表!',mtInformation,[mbyes],0);
result:=false;
exit;
end;
self.DataSet:=objAdoQuery;
if objAdoQuery.RecordCount<>0 then
begin
row_la:=0;
row_te:=0;
left_bj:=0;
j:=0;
re_width:=DetailBand1.Width;
m:=re_width div 100;
file://注意:是否放弃objAdoquery中的第一列
if haveFirstCol
then hafn:=0
else hafn:=1;
for i:=hafn to objAdoQuery.FieldCount-1 do
begin
if j=m then
begin
left_bj:=0;
row_la:=row_la+1;
row_te:=row_te+1;
j:=0;
ColumnHeaderBand1.Height:=ColumnHeaderBand1.Height+27;
DetailBand1.Height:=DetailBand1.Height+27;
end;
la:=TQRLabel.Create(self);
la.Caption:=objAdoQuery.Fields[i].FieldName;
la.Width:=100;
la.Height:=17;
la.Left:=left_bj;
la.Top:=30+(la.Height+10)*row_la;
la.Parent:=ColumnHeaderBand1 ;
te:=TQRDBText.Create(self);
te.DataSet:=objAdoQuery;
te.DataField:=objAdoQuery.Fields[i].FieldName;
te.Width:=100;
te.Height:=17;
te.Left:=left_bj;
te.Top:=30+(te.Height+10)*row_te;
te.Parent:=DetailBand1;
te.AutoStretch:=true;
left_bj:=(j+1)*105;
j:=j+1;
end;
end;
result:=true;
end;
end.
调用程序如下:
procedure TFrm_sbcx_yin.BitBtn_xxxx_dyClick(Sender: TObject);
var
qp:TQReport_lxr;
begin
qp:=TQReport_lxr.Create(self);
qp.bb_title.Caption:='设备类别查询';
if qp.bb_prepare(ADOQuery_xxxx,false)
then begin
qp.Prepare;
qp.Preview;
qp.hide;
end;
qp.free;
end;
本文地址:http://www.45fan.com/a/question/69961.html