今天在用 QuickReport 做报表时遇到一个问题,我要根据字段的值来用 QRimage 装载不同的图片,而这个 数据集里有多条记录,在预览前用
while not eof do
begin
end;
来做,可以把记录都显示出来,但图片都是同一幅图片,好像只是根据第一条记录来判断的,试了试把代码放在别的地方也不行。后来看了看别人做的例子,明白了
要在 subDetail 里的 beforPrint 事件中写这些代码,但是不要自己来处理这个循环。代码如下
procedure TFocReportVoucherForm.QRSubDetail1BeforePrint(
Sender: TQRCustomBand; var PrintBand: Boolean);
var
iPath:string;
begin
with query2 do
begin
// while not eof do // 去掉这个就能正常显示了
begin
if FieldByName('Design').AsString = 'Y' then
FocReportVoucherForm.QRIzz.Picture.LoadFromFile(iPath+'icon/checked.bmp')
else
FocReportVoucherForm.QRIzz.Picture.LoadFromFile(iPath+'icon/unchecked.bmp');
if FieldByName('Film').AsString = 'Y' then
FocReportVoucherForm.QRIsc.Picture.LoadFromFile(iPath+'icon/checked.bmp')
else
FocReportVoucherForm.QRIsc.Picture.LoadFromFile(iPath+'icon/unchecked.bmp');
if FieldByName('Proof').AsString = 'Y' then
FocReportVoucherForm.QRIdy.Picture.LoadFromFile(iPath+'icon/checked.bmp')
else
FocReportVoucherForm.QRIdy.Picture.LoadFromFile(iPath+'icon/unchecked.bmp');
if FieldByName('DigitalPrint').AsString = 'Y' then
FocReportVoucherForm.QRIsmky.Picture.LoadFromFile(iPath+'icon/checked.bmp')
else
FocReportVoucherForm.QRIsmky.Picture.LoadFromFile(iPath+'icon/unchecked.bmp');
if FieldByName('CTP').AsString = 'Y' then
FocReportVoucherForm.QRIzzzb.Picture.LoadFromFile(iPath+'icon/checked.bmp')
else
FocReportVoucherForm.QRIzzzb.Picture.LoadFromFile(iPath+'icon/unchecked.bmp');
if FieldByName('Printing').AsString = 'Y' then
FocReportVoucherForm.QRIys.Picture.LoadFromFile(iPath+'icon/checked.bmp')
else
FocReportVoucherForm.QRIys.Picture.LoadFromFile(iPath+'icon/unchecked.bmp');
if FieldByName('NormalProof').AsString = 'Y' then
FocReportVoucherForm.QRIcgdy.Picture.LoadFromFile(iPath+'icon/checked.bmp')
else
FocReportVoucherForm.QRIcgdy.Picture.LoadFromFile(iPath+'icon/unchecked.bmp');
if FieldByName('SpotColor').AsString = 'Y' then
FocReportVoucherForm.QRIzs.Picture.LoadFromFile(iPath+'icon/checked.bmp')
else
FocReportVoucherForm.QRIzs.Picture.LoadFromFile(iPath+'icon/unchecked.bmp');
if FieldByName('DigitalProof').AsString = 'Y' then
FocReportVoucherForm.QRIsmdy.Picture.LoadFromFile(iPath+'icon/checked.bmp')
else
FocReportVoucherForm.QRIsmdy.Picture.LoadFromFile(iPath+'icon/unchecked.bmp');
// next;
end;
end;
end;