请问怎样实现动态打印?(100分)

  • 主题发起人 主题发起人 mikeyao
  • 开始时间 开始时间
M

mikeyao

Unregistered / Unconfirmed
GUEST, unregistred user!
要求:可以让用户自己选择数据库中要打印的字段,系统根据字段长短安排报表中的间隔.
请问delphi有没有相对简单的实现方法?
 
本人曾实现过类似的功能,找印前把要打印的字段选出形成一个表,部份代码如下:
procedure inirepdyff;
var
lmc:string;
leftline,leftxm,ledth,nch,bitn:integer;
begin
leftline:=133;
leftxm:=135;
repdyff.QRShape1.Width:=133;
repdyff.QRShape10.Width:=133;
repdyff.QRShape11.Width:=133;
repdyff.QRShape12.Width:=133;
repdyff.QRLabel5.Caption:=trim(glname)+' '+repdyff.qrlabel5.caption;
with datamodule1.dyfeddo
begin
//dyfed
open;
first;
while not eofdo
begin
//eof1
if (copy(trim(fieldbyname('name').asstring),1,1)='A') and
(fieldbyname('dy').asboolean=true) and (fieldbyname('sy').asboolean=true)
then
begin
bitn:=fieldbyname('bn').asinteger;
ledth:=fieldbyname('ld').asinteger;
nch:=(ledth div 10)*2;
lmc:=trim(fieldbyname('mc').asstring);
if length(lmc)>nch then
lmc:=copy(lmc,1,nch);
with tqrlabel.Create(repdyff.qrband4)do
begin
parent:=repdyff.QRBand4;
top:=37;
height:=13;
left:=leftxm;
caption:=lmc;
end;

with tqrdbtext.Create(repdyff)do
begin
parent:=repdyff.QRBand2;
top:=10;
height:=13;
left:=leftxm;
case bitn of
0: mask:='0.';
1: mask:='0.0';
2: mask:='0.00';
end;
dataset:=datamodule1.Qdgzdy;
datafield:=fieldbyname('name').asstring;
end;
with tqrexpr.Create(repdyff)do
begin
parent:=repdyff.QRBand3;
top:=10;
height:=13;
left:=leftxm;
case bitn of
0: mask:='0.';
1: mask:='0.0';
2: mask:='0.00';
end;
expression:='sum'+'('+fieldbyname('name').asstring+')';
resetafterprint:=true;
end;

leftline:=leftline+ledth;
leftxm:=leftxm+ledth;
with tqrshape.Create(repdyff)do
begin
parent:=repdyff.QRBand3;
top:=1;
height:=39;
left:=leftline;
shape:=qrsvertline;
width:=1;
end;

with tqrshape.Create(repdyff)do
begin
parent:=repdyff.QRBand2;
top:=1;
height:=33;
left:=leftline;
shape:=qrsvertline;
width:=1;
end;

with tqrshape.Create(repdyff)do
begin
parent:=repdyff.QRBand4;
top:=27;
height:=33;
left:=leftline;
shape:=qrsvertline;
width:=1;
end;

repdyff.QRShape1.Width:=repdyff.qrshape1.Width+ledth;
repdyff.QRShape10.Width:=repdyff.qrshape10.Width+ledth;
repdyff.QRShape11.Width:=repdyff.qrshape11.Width+ledth;
repdyff.QRShape12.Width:=repdyff.qrshape12.Width+ledth;
end;
next;
end;
//eof1
if locate('name','YAA',[]) then
begin
//LOCA
if (fieldbyname('dy').asboolean=true) and (fieldbyname('sy').asboolean=true)
then
begin
//IF
bitn:=fieldbyname('bn').asinteger;
ledth:=fieldbyname('ld').asinteger;
nch:=(ledth div 10)*2;
lmc:=trim(fieldbyname('mc').asstring);
if length(lmc)>nch then
lmc:=copy(lmc,1,nch);
with tqrlabel.Create(repdyff.qrband4)do
begin
parent:=repdyff.QRBand4;
top:=37;
height:=13;
left:=leftxm;
caption:=lmc;
end;

with tqrdbtext.Create(repdyff)do
begin
parent:=repdyff.QRBand2;
top:=10;
height:=13;
left:=leftxm;
case bitn of
0: mask:='0.';
1: mask:='0.0';
2: mask:='0.00';
end;
dataset:=datamodule1.Qdgzdy;
datafield:=fieldbyname('name').asstring;
end;
with tqrexpr.Create(repdyff)do
begin
parent:=repdyff.QRBand3;
top:=10;
height:=13;
left:=leftxm;
case bitn of
0: mask:='0.';
1: mask:='0.0';
2: mask:='0.00';
end;
expression:='sum'+'('+fieldbyname('name').asstring+')';
resetafterprint:=true;
end;

leftline:=leftline+ledth;
leftxm:=leftxm+ledth;
with tqrshape.Create(repdyff)do
begin
parent:=repdyff.QRBand3;
top:=1;
height:=39;
left:=leftline;
shape:=qrsvertline;
width:=1;
end;

with tqrshape.Create(repdyff)do
begin
parent:=repdyff.QRBand2;
top:=1;
height:=33;
left:=leftline;
shape:=qrsvertline;
width:=1;
end;

with tqrshape.Create(repdyff)do
begin
parent:=repdyff.QRBand4;
top:=27;
height:=33;
left:=leftline;
shape:=qrsvertline;
width:=1;
end;

repdyff.QRShape1.Width:=repdyff.qrshape1.Width+ledth;
repdyff.QRShape10.Width:=repdyff.qrshape10.Width+ledth;
repdyff.QRShape11.Width:=repdyff.qrshape11.Width+ledth;
repdyff.QRShape12.Width:=repdyff.qrshape12.Width+ledth;
end;
//IF
end;
//loca
first;
while not eofdo
begin
//eof1
if (copy(trim(fieldbyname('name').asstring),1,1)='B') and
(fieldbyname('dy').asboolean=true) and (fieldbyname('sy').asboolean=true)
then
begin
//if
bitn:=fieldbyname('bn').asinteger;
ledth:=fieldbyname('ld').asinteger;
nch:=(ledth div 10)*2;
lmc:=trim(fieldbyname('mc').asstring);
if length(lmc)>nch then
lmc:=copy(lmc,1,nch);
with tqrlabel.Create(repdyff.qrband4)do
begin
parent:=repdyff.QRBand4;
top:=37;
height:=13;
left:=leftxm;
caption:=lmc;
end;

with tqrdbtext.Create(repdyff)do
begin
parent:=repdyff.QRBand2;
top:=10;
height:=13;
left:=leftxm;
case bitn of
0: mask:='0.';
1: mask:='0.0';
2: mask:='0.00';
end;
dataset:=datamodule1.Qdgzdy;
datafield:=fieldbyname('name').asstring;
end;
with tqrexpr.Create(repdyff)do
begin
parent:=repdyff.QRBand3;
top:=10;
height:=13;
left:=leftxm;
case bitn of
0: mask:='0.';
1: mask:='0.0';
2: mask:='0.00';
end;
expression:='sum'+'('+fieldbyname('name').asstring+')';
resetafterprint:=true;
end;

leftline:=leftline+ledth;
leftxm:=leftxm+ledth;
with tqrshape.Create(repdyff)do
begin
parent:=repdyff.QRBand3;
top:=1;
height:=39;
left:=leftline;
shape:=qrsvertline;
width:=1;
end;

with tqrshape.Create(repdyff)do
begin
parent:=repdyff.QRBand2;
top:=1;
height:=33;
left:=leftline;
shape:=qrsvertline;
width:=1;
end;

with tqrshape.Create(repdyff)do
begin
parent:=repdyff.QRBand4;
top:=27;
height:=33;
left:=leftline;
shape:=qrsvertline;
width:=1;
end;

repdyff.QRShape1.Width:=repdyff.qrshape1.Width+ledth;
repdyff.QRShape10.Width:=repdyff.qrshape10.Width+ledth;
repdyff.QRShape11.Width:=repdyff.qrshape11.Width+ledth;
repdyff.QRShape12.Width:=repdyff.qrshape12.Width+ledth;
end;
//if
next;
end;
//eof1
if locate('name','YCC',[]) then
begin
//LOCA
if (fieldbyname('dy').asboolean=true) and (fieldbyname('sy').asboolean=true)
then
begin
//IF
bitn:=fieldbyname('bn').asinteger;
ledth:=fieldbyname('ld').asinteger;
nch:=(ledth div 10)*2;
lmc:=trim(fieldbyname('mc').asstring);
if length(lmc)>nch then
lmc:=copy(lmc,1,nch);
with tqrlabel.Create(repdyff.qrband4)do
begin
parent:=repdyff.QRBand4;
top:=37;
height:=13;
left:=leftxm;
caption:=lmc;
end;

with tqrdbtext.Create(repdyff)do
begin
parent:=repdyff.QRBand2;
top:=10;
height:=13;
left:=leftxm;
case bitn of
0: mask:='0.';
1: mask:='0.0';
2: mask:='0.00';
end;
dataset:=datamodule1.Qdgzdy;
datafield:=fieldbyname('name').asstring;
end;
with tqrexpr.Create(repdyff)do
begin
parent:=repdyff.QRBand3;
top:=10;
height:=13;
left:=leftxm;
case bitn of
0: mask:='0.';
1: mask:='0.0';
2: mask:='0.00';
end;
expression:='sum'+'('+fieldbyname('name').asstring+')';
resetafterprint:=true;
end;

leftline:=leftline+ledth;
leftxm:=leftxm+ledth;
with tqrshape.Create(repdyff)do
begin
parent:=repdyff.QRBand3;
top:=1;
height:=39;
left:=leftline;
shape:=qrsvertline;
width:=1;
end;

with tqrshape.Create(repdyff)do
begin
parent:=repdyff.QRBand2;
top:=1;
height:=33;
left:=leftline;
shape:=qrsvertline;
width:=1;
end;

with tqrshape.Create(repdyff)do
begin
parent:=repdyff.QRBand4;
top:=27;
height:=33;
left:=leftline;
shape:=qrsvertline;
width:=1;
end;

repdyff.QRShape1.Width:=repdyff.qrshape1.Width+ledth;
repdyff.QRShape10.Width:=repdyff.qrshape10.Width+ledth;
repdyff.QRShape11.Width:=repdyff.qrshape11.Width+ledth;
repdyff.QRShape12.Width:=repdyff.qrshape12.Width+ledth;
end;
//IF
end;
//loca
end;
//dyfed
with tqrlabel.Create(repdyff.qrband4)do
begin
parent:=repdyff.QRBand4;
top:=37;
height:=13;
left:=leftxm+20;
caption:='签名';
end;
leftline:=leftline+60;
leftxm:=leftxm+60;
with tqrshape.Create(repdyff)do
begin
parent:=repdyff.QRBand3;
top:=1;
height:=39;
left:=leftline;
shape:=qrsvertline;
width:=1;
end;

with tqrshape.Create(repdyff)do
begin
parent:=repdyff.QRBand2;
top:=1;
height:=33;
left:=leftline;
shape:=qrsvertline;
width:=1;
end;

with tqrshape.Create(repdyff)do
begin
parent:=repdyff.QRBand4;
top:=27;
height:=33;
left:=leftline;
shape:=qrsvertline;
width:=1;
end;

repdyff.QRShape1.Width:=repdyff.qrshape1.Width+60;
repdyff.QRShape10.Width:=repdyff.qrshape10.Width+60;
repdyff.QRShape11.Width:=repdyff.qrshape11.Width+60;
repdyff.QRShape12.Width:=repdyff.qrshape12.Width+60;
with tqrlabel.Create(repdyff.qrband4)do
begin
parent:=repdyff.QRBand4;
top:=37;
height:=13;
left:=leftxm+2;
caption:='序号';
end;
with tqrdbtext.Create(repdyff)do
begin
parent:=repdyff.QRBand2;
top:=10;
height:=13;
left:=leftxm+5;
dataset:=datamodule1.Qdgzdy;
datafield:='no';
end;

leftline:=leftline+30;
//leftxm:=leftxm+30;
with tqrshape.Create(repdyff)do
begin
parent:=repdyff.QRBand3;
top:=1;
height:=39;
left:=leftline;
shape:=qrsvertline;
width:=1;
end;

with tqrshape.Create(repdyff)do
begin
parent:=repdyff.QRBand2;
top:=1;
height:=33;
left:=leftline;
shape:=qrsvertline;
width:=1;
end;

with tqrshape.Create(repdyff)do
begin
parent:=repdyff.QRBand4;
top:=27;
height:=33;
left:=leftline;
shape:=qrsvertline;
width:=1;
end;

repdyff.QRShape1.Width:=repdyff.qrshape1.Width+30;
repdyff.QRShape10.Width:=repdyff.qrshape10.Width+30;
repdyff.QRShape11.Width:=repdyff.qrshape11.Width+30;
repdyff.QRShape12.Width:=repdyff.qrshape12.Width+30;
end;
 
接受答案了.
 
后退
顶部