Uses <var> markers and OnGetVariableValue
to put in titles and cells values that are not fields of the dataset,
and VariableRowIndex
to compute a value for the row being drawn.
Price<br>(<var>Currency</var>).// FormCreate
Grid1.ColumnByFieldName('Price').Title.Caption := 'Price<br>(<var>Currency</var>)';
Grid1.HeaderHeight := 40; // room for the second line of the title
Grid1.RowHeight := 36; // room for two lines in the cells
Besides EgFireGrid: System.SysUtils
(SameText, IntToStr,
FormatSettings, Date) and
System.Variants (VarIsNull,
VarToDateTime).
procedure TForm1.Grid1BeforeDrawCell(Sender: TObject; Column: TEgFireGridColumn; RowIndex: Integer;
Cell: TEgFireGridCellControl; var Text: string);
begin
if SameText(Column.FieldName, 'Name') then
// Both names are fields: the grid replaces them with the fields' text in this row
Text := '<var>Name</var><br><var>Category</var>'
else if SameText(Column.Title.Caption, 'Updated') then
Text := '<var>DaysSinceUpdate</var> days';
end;
procedure TForm1.Grid1GetVariableValue(Sender: TObject; const VarID: string; var Value: string);
var
UpdatedAt: Variant;
begin
if SameText(VarID, 'Currency') then
Value := FormatSettings.CurrencyString
else if SameText(VarID, 'DaysSinceUpdate') and (Grid1.VariableRowIndex >= 0) then
begin
UpdatedAt := Grid1.RowSource.GetValue(Grid1.VariableRowIndex, 'UpdatedAt');
if not VarIsNull(UpdatedAt) then
Value := IntToStr(Trunc(Date - VarToDateTime(UpdatedAt)));
end;
end;
OnGetVariableValue is asked only for the other
names, and for every marker in a title (a title belongs to no row).VariableRowIndex is the window row of
the marker being resolved, -1 in a title; the handler reads that row’s
fields with RowSource.GetValue.<br> is a line break. The row
and title heights do not grow by themselves, hence the two heights in
the setup.