FPReport aggregate wrong calculation
Summary
When using a group header and footer, the aggregate (sum) is not calculated correctly.
System Information
- Operating system: Arch Linux (should be OS independent)
- Processor architecture: x86-64
- Compiler version: Lazarus 3.99 (rev main_3_99-2635-g55ac08a505) FPC 3.3.1 x86_64-linux-gtk2
- Device: Computer
Steps to reproduce
See the example project below. It exports the report to PDF, which shows wrong aggregates (sum).
Example Project
program project1;
{$mode objfpc}{$H+}
uses
Classes, SysUtils,
fpreport, jsonparser, fpreportjson, fpreportpdfexport, fpttf, dynlibs;
const
JSONDATA =
'[' +
' { "cont": "Europe", "city": "Amsterdam", "members": 10 }, ' +
' { "cont": "Europe", "city": "Brussels", "members": 20 }, ' +
' { "cont": "America", "city": "Chicago", "members": 5 } ' +
']';
var
rpt: TFPReport;
repdata: TFPReportJSONData;
p: TFPReportPage;
gh: TFPReportGroupHeaderBand;
db: TFPReportDataBand;
gf: TFPReportGroupFooterBand;
exp: TFPReportExporter;
begin
PaperManager.RegisterStandardSizes;
gTTFontCache.ReadStandardFonts;
rpt := TFPReport.Create(nil);
repdata := TFPReportJSONData.Create(nil);
repdata.JSON := JSONDATA;
p := TFPReportPage.Create(rpt);
p.Orientation := poPortrait;
p.PageSize.PaperName := 'A4';
p.Font.Name := 'LiberationSans';
p.Margins.Left := 30;
p.Margins.Top := 20;
p.Margins.Right := 30;
p.Margins.Bottom := 20;
p.Data := repdata;
gh := TFPReportGroupHeaderBand.Create(p);
gh.Layout.Height := 10;
gh.GroupCondition := 'cont';
gh.Data := repdata;
with TFPReportMemo.Create(gh) do
begin
Layout.SetPosition(5, 0, 100, 10);
Text := 'Group header for [cont]';
end;
db := TFPReportDataBand.Create(p);
db.Layout.Height := 10;
db.Data := repdata;
with TFPReportMemo.Create(db) do
begin
Layout.SetPosition(5, 0, 100, 10);
Text := 'Continent: [cont]; City: [city]; Members: [members]';
end;
gf := TFPReportGroupFooterBand.Create(p);
gf.Layout.Height := 10;
gf.GroupHeader := gh;
with TFPReportMemo.Create(gf) do
begin
Layout.SetPosition(5, 0, 100, 10);
Text := 'Sum of members: [sum(members)]';
Font.Color := clRed;
end;
rpt.RunReport;
exp := TFPReportExportPDF.Create(nil);
exp.SetFileName('test.pdf');
rpt.RenderReport(exp);
exp.Free;
repdata.Free;
rpt.Free;
end.
What is the current bug behavior?
The output shows:
Group header for Europe
Continent: Europe; City: Amsterdam; Members: 10
Continent: Europe; City: Brussels; Members: 20
Sum of members: 35
Group header for America
Continent: America; City: Chicago; Members: 5
Sum of members: 0
What is the expected (correct) behavior?
The first sum should be 25; the second sum should be 5.