unit Clrgrid;
interface
uses winTypes, classes, Graphics, grids;
type
TColorEvent =
procedure (Sender: TObject; ARow, ACol: Longint;
AState: TGridDrawState;
ABrush: TBrush; AFont: TFont )
of object;
TColorStringGrid =
class(TStringGrid)
private
FonGetCellColor: TColorEvent;
protected
procedure DrawCell(ACol, ARow: Longint; ARect: TRect;
AState: TGridDrawState);
override;
Published
property OnGetCellColor: TColorEvent
read FOnGetCellColor
write FOnGetCellColor;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('
Samples',[TColorStringGrid]);
end;
procedure TColorStringGrid.DrawCell(ACol, ARow: Longint; ARect: TRect;
AState: TGridDrawState);
begin
if Assigned(FOnGetCellColor)
then
FOnGetCellColor(Self, ARow, ACol, AState, Canvas.Brush, Canvas.Font);
inherited DrawCell(ACol, ARow, ARect, AState);
end;[/quote]
Und hier wird überprüft, ob FOnGetCellColor Assigned ist, bevor die Funktion zum Ausfüllen der Grid gestartet wird:
[quote]
if Assigned(FOnGetCellColor)
then
FOnGetCellColor(Self, ARow, ACol, AState, Canvas.Brush, Canvas.Font);
inherited DrawCell(ACol, ARow, ARect, AState);