Ganz genauso (nur ohne das
with
) habe ich es auch gemacht, wieder etwas gelernt
Delphi-Quellcode:
TDBGridHelper = class helper for TDBGrid
public procedure writeText(const inRect: TRect; const text: String);
end;
procedure TForm1.DBGrid1DrawColumnCell(
Sender: TObject;
const Rect: TRect;
DataCol: Integer;
Column: TColumn;
State: TGridDrawState
);
var
displayText: String;
begin
if (Column.FieldName='someFancyField') and Assigned(Column.Field) then begin
displayText := '***' + Column.Field.DisplayText + '***';
(Sender as TDBGrid).writeText(Rect, displayText);
end else
(Sender as TDBGrid).DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
procedure TDBGridHelper.writeText(
const inRect: TRect;
const text: String
);
const
someMagicOffsetPx = 2; // Siehe TDBGrid::DefaultDrawColumnCell
begin
Canvas.FillRect(inRect);
Canvas.TextRect(
inRect,
inRect.Left + someMagicOffsetPx,
inRect.Top + someMagicOffsetPx,
text
);
end;