if
((DataSource1.DataSet).Active=true) and
((DataSource1.DataSet).RecordCount〉0)
then begin printer.BeginDoc; (DataSo
e1.DataSet).First; while not (DataSource1.DataSet).Eof do begin
//打印DBGrid中的所有列 for i:=0 to DBGrid1.FieldCount-1 do
begin //假如所要打印的列超出了打印范围,则忽略该列 if
(x+DBGrid1.Columns.Items[i].Width*PointScale)〈=(Printer.PageWidth-PointX*RightBlank)
then begin //画表格线 //每页的第一行打印表头
Printer.Canvas.Rectangle(x,y,x+DBGrid1.Columns. Items[i].Width*PointScale,y+PrintStep);
if y=PointY*TopBlank then
Printer.Canvas.TextOut(x+8,y+8,DBGrid1.Columns[i].Title.Caption)
else
Printer.Canvas.TextOut(x+8,y+8,DBGrid1.Fields[i].asString); end;
//计算下一列的横坐标
if not
(y=PointY*TopBlank) then (DataSource1.DataSet).next;
x:=PointX*LeftBlank; y:=y+PrintStep; //换页 if
(y+PrintStep)〉(Printer.PageHeight-PointY*BottomBlank) then begin
Printer.NewPage; y:=PointY*TopBlank; end; end;