用Tquickreport来做stringgrid的打印及预览(0分)

  • 主题发起人 主题发起人 ww20000309
  • 开始时间 开始时间
W

ww20000309

Unregistered / Unconfirmed
GUEST, unregistred user!
看了delphi自带的domes想的,有更好的想法了探讨一下;
以下的源程序:
//***************************************unit1**********************************
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, QuickRpt, StdCtrls, Grids;
type
TForm1 = class(TForm)
Button1: TButton;
StringGrid1: TStringGrid;
procedure Button1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
uses unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
form2.SomeList1:=Tstringlist.Create;
form2.SomeList2:=Tstringlist.Create;
form2.SomeList3:=Tstringlist.Create;
form2.SomeList4:=Tstringlist.Create;
for i:=0 to stringgrid1.RowCount -1do
begin
form2.SomeList1.Add(stringgrid1.Cells[0,i]);
form2.SomeList2.Add(stringgrid1.Cells[1,i]);
form2.SomeList3.Add(stringgrid1.Cells[2,i]);
form2.SomeList4.Add(stringgrid1.Cells[3,i]);
end;
form2.QuickRep1.Preview ;
end;

procedure TForm1.FormActivate(Sender: TObject);
var
i,j:integer;
begin
stringgrid1.RowCount :=150;
for i:=0 to 149do
for j:=0 to 4 do
stringgrid1.Cells[j,i]:=inttostr(i+j);
end;

end.
//*******************************************unit2*****************************
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, QuickRpt, QRCtrls;
type
TForm2 = class(TForm)
QuickRep1: TQuickRep;
QRBand1: TQRBand;
QRBand2: TQRBand;
QRLabel1: TQRLabel;
QRLabel2: TQRLabel;
QRLabel3: TQRLabel;
QRLabel4: TQRLabel;
QRLabel5: TQRLabel;
QRLabel6: TQRLabel;
QRLabel7: TQRLabel;
QRLabel8: TQRLabel;
QRBand3: TQRBand;
QRLabel9: TQRLabel;
procedure QuickRep1BeforePrint(Sender: TCustomQuickRep;
var PrintReport: Boolean);
procedure QuickRep1NeedData(Sender: TObject;
var MoreData: Boolean);
private
{ Private declarations }
CurrentIndex: integer;
public
SomeList1: TStringlist;
SomeList2: TStringlist;
SomeList3: TStringlist;
SomeList4: TStringlist;
{ Public declarations }
end;

var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.QuickRep1BeforePrint(Sender: TCustomQuickRep;
var PrintReport: Boolean);
begin
CurrentIndex := 0;
end;

procedure TForm2.QuickRep1NeedData(Sender: TObject;
var MoreData: Boolean);
begin
MoreData := (CurrentIndex < SomeList1.Count);
if MoreData then
begin
QRLabel5.Caption := SomeList1[CurrentIndex];
QRLabel6.Caption := SomeList2[CurrentIndex];
QRLabel7.Caption := SomeList3[CurrentIndex];
QRLabel8.Caption := SomeList4[CurrentIndex];
QuickRep1.QRPrinter.Progress := (Longint(CurrentIndex) * 100) div SomeList1.Count;
end
else
QuickRep1.QRPrinter.Progress := 100;
Inc(CurrentIndex);
end;

end.
 

Similar threads

后退
顶部