1、设置QuickReport的DataSet为空。
2、在QuickReport的BeforePrint里面将要显示的数据集合初始化,如Query1.First;
3、在OnNeedData里面写代码,同时设置MoreData的状态、移动数据集合
如:QrLabel1.Caption:=Query1.FieldByName('Col1').AsString;
Query1.Next;
MoreData:=Not Query1.Eof;
这样就OK了!
https://wedelphi.com/t/92391/
quickreport 的 OnNeedData:
procedure TForm1.QuickRep1NeedData(Sender: TObject;
var MoreData: Boolean);
begin
moredata:=true;
if not table1.Eof then
begin
begin
qrlabel1.Caption := table1.fieldbyname('Name').AsString;
//subDetail中要显示的数据
qrlabel2.Caption := table1.fieldbyname('Age').AsString;
end;
table1.Next;
end
else
//每页显示五行,不足用空行补齐
if nRow < 5 then
begin
qrlabel1.Caption := '';
qrlabel2.Caption := '';
end;
if nRow = 5 then
begin
moredata := false;
table1.First;
nRow := 0;
end;
Inc(nRow);
end;
https://wedelphi.com/t/302356/
如果你有quickreport的源代码可以这样改造,下面代码是需要加入的。
由于这里不一定说的清楚,你如果写过控件可以自己改造,代码就这些,
如果不行可以和我单独交流: TQrCustomController = class(TComponent) {控制}
private
FDetailPerPage: integer;
procedure SetDeatilPerPage(APerPage: integer);
public
property DetailPerPage: integer read FDetailPerPage write SetDeatilPerPage;
end;
TCustomQrReport = class(TQrBasePanel)
private
FDetailPerPage: integer;
procedure SetDeatilPerPage(APerPage: integer);
public
procedure PrintBandchildNone(ABand: TNoteCustomBand); {打印但没有孩子}
property DetailPerPage: integer read FDetailPerPage write SetDeatilPerPage;
end;
procedure TCustomNotePaint.PrintBandchildNone(ABand: TNoteCustomBand);
{打印但没有孩子}
var
dmy: integer;
begin
if ABand <> nil then
begin
if ABand.AlignToBottom then
begin
if Page.Orientation = poPortrait then
dmy := round(QRPrinter.PaperLength - Page.BottomMargin -
ABand.Size.Length - FPageFooterSize)
else
dmy := round(QRPrinter.PaperWidth - Page.BottomMargin -
ABand.Size.Length - FPageFooterSize);
if dmy > CurrentY then
CurrentY := dmy;
end;
ABand.PrintNoChild;
end;
end;
//加入固定数目的空白行procedure TQrController.PrintBlankFooter(Anum: integer);
var
I, j: integer;
TmpBand: TNoteband;
TmpColor: tColor;
begin
if Anum = 0 then
exit;
if Anum = FDetailPerPage then
exit;
TmpBand := TQrBand.Create(FParentReport);
TmpBand.BandType := rbSummary;
TmpBand.Frame.DrawLeft := true;
TmpBand.Frame.DrawRight := true;
TmpBand.Frame.DrawBottom := true;
if ((FDetail <> nil) and (FDetail.ControlCount > 0)) then
TmpColor := TQrCustomLabel(FDetail.Controls[0]).Font.Color;
for I := Anum - 1 downto 0 do
begin
for j := 0 to FDetail.ControlCount - 1 do
begin
TQrCustomLabel(FDetail.Controls[j]).Font.Color := FDetail.Color;
{颜色为底色}
end;
FParentReport.PrintBandchildNone(FDetail);
{有效但造成了最后一条记录的重复计算,修改后已经解决}
for j := 0 to FDetail.ControlCount - 1 do
begin
TNoteCustomLabel(FDetail.Controls[j]).Font.Color := TmpColor;
end;
end;
TmpBand.Free;
end;
///Suny modified 2000.3.15 one functionprocedure TQrCustomController.SetDeatilPerPage(APerPage: integer);
begin
FDetailPerPage := APerPage;
end;///Suny modified 2000.3.15 one functionprocedure TCustomQrReport.SetDeatilPerPage(APerPage: integer);
begin
FDetailPerPage := APerPage;
Controller.DetailPerPage := AperPage;
end;
在procedure TQrController.Execute;函数中找到:
ParentReport.QRPrinter.Progress := (Longint(DetailNumber) * 100) div
RecCount;
一句,在其后加入
if FDetailPerPage <> 0 then
begin
if (FDetailNumber mod FDetailPerPage) = 0 then
begin
if assigned(FFooter) then
begin
if (SelfCheck is TCustomNotePaint) and
FFooter.AlignToBottom then
;
// ParentReport.FPageFooterSize := 0;
if (FFooter <> nil) and (ParentReport.PageNumber = 0) then
ParentReport.NewPage;
ParentReport.PrintBand(FFooter);
end;再找到:
CheckLastGroupFooters;
PrintGroupFooters;
if assigned(FFooter) then
begin
if (SelfCheck is TCustomNotePaint) and
FFooter.AlignToBottom then
;
在其前加入:
if FDetailPerPage <> 0 then
if detailNumber = RecCount then
PrintBlankFooter(FDetailPerPage - (RecCount mod FDetailPerPage));
http://www.debugease.com/delphi/4231392.html