我用QR实现了具体做法如下:
打印按钮的代码:
procedure Tfrmingoods.printbuttonClick(Sender: TObject);
var
i:integer;
begin
if not assigned(frmpevingoods) then
begin
application.CreateForm(Tfrmpevingoods,frmpevingoods);
frmpevingoods.outgoodsid.Caption :=danjutext.Caption ;
frmpevingoods.clientshop.Caption :=supplyname.Text ;
frmpevingoods.currentdate.Caption :=datetext.Caption ;
frmpevingoods.operatorname.Caption :=operatename.Text ;
frmpevingoods.SomeList1:=Tstringlist.Create ;
frmpevingoods.SomeList2:=Tstringlist.Create ;
frmpevingoods.SomeList3:=Tstringlist.Create ;
frmpevingoods.SomeList5:=Tstringlist.Create ;
for i:=1 to listgrid.RowCount -1do
begin
frmpevingoods.SomeList1.Add(listgrid.Cells[2,i]);
frmpevingoods.SomeList2.Add(listgrid.Cells[5,i]);
frmpevingoods.SomeList3.Add(listgrid.Cells[6,i]);
frmpevingoods.SomeList5.Add(listgrid.Cells[7,i]);
end;
frmpevingoods.paycount.Caption :=totalmoney.Text ;
frmpevingoods.currentcount.Caption :=currentmoney.Text ;
frmpevingoods.paymentclass.Caption :=paymentbox.Text ;
frmpevingoods.QuickRep1.Preview ;
if assigned(frmpevingoods) then
frmpevingoods:=nil;
end;
end;
报表的代码如下:
unit pevingoods;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, QRCtrls, QuickRpt, ExtCtrls;
type
Tfrmpevingoods = class(TForm)
QuickRep1: TQuickRep;
QRBand1: TQRBand;
QRLabel1: TQRLabel;
QRSubDetail1: TQRSubDetail;
goodsname: TQRLabel;
outcount: TQRLabel;
outprice: TQRLabel;
totalmoney: TQRLabel;
GroupFooterBand1: TQRBand;
QRLabel6: TQRLabel;
QRLabel12: TQRLabel;
QRLabel13: TQRLabel;
QRLabel14: TQRLabel;
paycount: TQRLabel;
currentcount: TQRLabel;
paymentclass: TQRLabel;
QRShape2: TQRShape;
GroupHeaderBand1: TQRBand;
QRLabel7: TQRLabel;
QRLabel8: TQRLabel;
QRLabel9: TQRLabel;
QRLabel11: TQRLabel;
QRBand2: TQRBand;
QRLabel2: TQRLabel;
QRLabel3: TQRLabel;
QRLabel4: TQRLabel;
QRLabel5: TQRLabel;
outgoodsid: TQRLabel;
clientshop: TQRLabel;
currentdate: TQRLabel;
operatorname: TQRLabel;
QRShape1: TQRShape;
procedure QuickRep1BeforePrint(Sender: TCustomQuickRep;
var PrintReport: Boolean);
procedure QRSubDetail1NeedData(Sender: TObject;
var MoreData: Boolean);
private
{ Private declarations }
CurrentIndex: integer;
public
{ Public declarations }
SomeList1: TStringlist;
SomeList2: TStringlist;
SomeList3: TStringlist;
SomeList5: TStringlist;
end;
var
frmpevingoods: Tfrmpevingoods;
implementation
{$R *.dfm}
procedure Tfrmpevingoods.QuickRep1BeforePrint(Sender: TCustomQuickRep;
var PrintReport: Boolean);
begin
CurrentIndex:=0;
end;
procedure Tfrmpevingoods.QRSubDetail1NeedData(Sender: TObject;
var MoreData: Boolean);
begin
MoreData := (CurrentIndex < SomeList1.Count);
if MoreData then
begin
goodsname.Caption := SomeList1[CurrentIndex];
outcount.Caption := SomeList2[CurrentIndex];
outprice.Caption := SomeList3[CurrentIndex];
totalmoney.Caption := SomeList5[CurrentIndex];
end;
Inc(CurrentIndex);
end;
end.