Déclarer une propriété TFont dans un composant
Dans la dbGrid native de lazarus, il n'est pas possible de modifier la Font d'une ligne sélectionnée :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| procedure TCustomDBGrid.DoPrepareCanvas(aCol, aRow: Integer;
aState: TGridDrawState);
var
DataCol: Integer;
IsSelected: boolean;
begin
if (ARow>=FixedRows) then begin
if not DefaultDrawing then begin
GetSelectedState(aState, IsSelected);
if IsSelected then begin
Canvas.Brush.Color := SelectedColor;
Canvas.Font.Color := clHighlightText;
end;
end;
if Assigned(OnPrepareCanvas) then begin
DataCol := ColumnIndexFromGridColumn(aCol);
if DataCol>=0 then
OnPrepareCanvas(Self, DataCol, TColumn(Columns[DataCol]), aState);
end;
end;
end; |
Je remplace donc dans ma propre dbGrid : Canvas.Font.Color := clHighlightText; par Canvas.Font:= FSelectedFont.
Je déclare la nouvelle propriété ainsi :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| TlzDbGrid = class(TDbGrid)
private
{ Private declarations }
FSelectedFont : TFont;
procedure SetSelectedFont(Value: TFont);
[...]
end;
constructor TlzDbGrid.Create(AOwner: TComponent);
var
AGrid: TCustomGrid;
begin
inherited Create(AOwner);
FSelectedFont := TFont.Create;
FSelectedFont := aGrid.Font;
end;
end;
destructor TlzDbGrid.Destroy;
begin
FreeThenNil(FSelectedFont);
inherited Destroy;
end;
procedure TlzDbGrid.SetSelectedFont(Value : Tfont);
var
AGrid: TCustomGrid;
begin
if Value<>nil then
FSelectedFont.Assign(Value)
else
FSelectedFont := agrid.Font;
end; |
Je passe par la Font d'une CustomGrid pour éviter un problème de nil si FSelectedFont n'est pas initialisée. Mais visiblement cela ne fonctionne pas. En plus j'ai un doute concernant l'affectation d'une TFont : FSelectedFont.Assign(Value) ou FSelectedFont := agrid.Font; ?
Je suis preneur de toute aide. Merci. Gilles