報表情境1 (未使用GroupBand)
procedure TForm1.DetailBand1AfterPrint(Sender: TQRCustomBand; BandPrinted: Boolean);
var iCurrencyY, iPaperLength, iPrintY, iCount, iLoopBandHeight, iBottomMargin,
iPageFooterBand, iQRGroupFooter:Integer;
begin
//檢查最後一筆
if ADOQuery1.RecNo=ADOQuery1.RecordCount then
begin
iPaperLength := QuickRep1.QRPrinter.PaperLength; //報表高度
iCurrencyY := QuickRep1.CurrentY; //目前輸出的高度
iLoopBandHeight := Ceil(QRLoopBand1.Size.Length); //LoopBand 的高度
iPageFooterBand := Ceil(PageFooterBand1.Size.Length); //PageFooterBand 的高度
iBottomMargin := Ceil(QuickRep1.Page.BottomMargin); //報表邊界Bottom的高度
iPrintY := iPaperLength - iCurrencyY - iPageFooterBand - iBottomMargin; //LoopBand 輸出的高度
iCount := iPrintY div iLoopBandHeight;
QRLoopBand1.PrintCount := iCount;
end;
報表情境2 (使用GroupBand)
procedure TForm1.QuickRep2StartPage(Sender: TCustomQuickRep);
begin
//在報表上放置QRExpr1,借來運算QRGroup.Expression運算後的結果
QRExpr1.Expression := QRGroup2.Expression;
QRExpr1.Enabled := False;
end;
procedure TForm1.DetailBand1AfterPrint(Sender: TQRCustomBand; BandPrinted: Boolean);
var iCurrencyY, iPaperLength, iPrintY, iCount, iLoopBandHeight, iBottomMargin,
iPageFooterBand, iQRGroupFooter:Integer;
sCurValue, sNextValue:String;
begin
//取得目前以及下一筆資料的運算結果做比對
sCurValue := QRExpr1.Value.StringVal;
adoQuery1.Next;
sNextValue := sCurValue;
if not adoQuery1.eof then
begin
sNextValue := QRExpr1.Value.StringVal;
adoquery1.Prior;
end;
//如果是最後一筆,或是前後筆資料不吻合,就使用LoopBand填滿
iCount := 0;
if (ADOQuery1.RecNo=ADOQuery1.RecordCount) or (sCurValue<>sNextValue) then
begin
iPaperLength := QuickRep2.QRPrinter.PaperLength; //報表高度
iCurrencyY := QuickRep2.CurrentY; //目前輸出的高度
iLoopBandHeight := Ceil(QRLoopBand2.Size.Length); //LoopBand 的高度
iQRGroupFooter := Ceil(QRGroupFooter2.Size.Length); //GroupFooter 的高度
iPageFooterBand := Ceil(PageFooterBand2.Size.Length); //PageFooter 的高度
iBottomMargin := Ceil(QuickRep2.Page.BottomMargin); //報表邊界Bottom的高度
iPrintY := iPaperLength - iCurrencyY - iPageFooterBand - iQRGroupFooter - iBottomMargin;
iCount := iPrintY div iLoopBandHeight;
end;
QRLoopBand2.PrintCount := iCount;
end;