Delphi UniGUI Grid with Summary
We’ll see how to make a grid with a Summary line at the end. And it’s very easy to do, like everything in UniGUI. It looks like this
First we need to calculate the final results, this is done in the OnColumnSummary event
procedure TMainForm.UniDBGridColumnSummary(Column: TUniDBGridColumn;
GroupFieldValue: Variant);
begin
if SameText(Column.FieldName, ‘quantity’) then
begin
if Column.AuxValue = NULL then Column.AuxValue:=0;
Column.AuxValue := Column.AuxValue + Column.Field.AsInteger;
end
else if SameText(Column.FieldName, ‘unitprice’) then
begin
if Column.AuxValue = NULL then Column.AuxValue:=0.0;
Column.AuxValue := Column.AuxValue + (Column.Field.AsFloat * ClientDataSet1Quantity.AsInteger);
end;
end;
Column.AuxValue is some buffer, as I understand it, where you can add the summation by column.
Now we need to output the results as follows
procedure TMainForm.UniDBGrid1ColumnSummaryResult(Column: TUniDBGridColumn;
GroupFieldValue: Variant; Attribs: TUniCellAttribs; var Result: string);
var
I : Integer;
F : Real;
begin
if SameText(Column.FieldName, ‘quantity’) then
begin
I:=Column.AuxValue;
Result:=Format(‘Total Units: %d’, [I]);
Attribs.Font.Style:=[fsBold];
Attribs.Font.Color:=clGreen;
end
else if SameText(Column.FieldName, ‘unitprice’) then
begin
F:=Column.AuxValue;
Result:=’Total Cost: ‘+FormatCurr(‘0,0.00 ‘, F) + FmtSettings.CurrencyString;
Attribs.Font.Style:=[fsBold];
Attribs.Font.Color:=clNavy;
end;
Column.AuxValue:=NULL;
end;
In principle, it’s quite simple!