I just had a look at the source of TStringGrid
. The Row
property is inherited from TCustomGrid
(via TDrawGrid
and TCustomDrawGrid
), where it is defined as
property Row: Longint read FCurrent.Y write SetRow;
as you say. SetRow
calls FocusCell
whichs calls MoveCurrent
. This one calls SelectCell
. This is a virtual function, and although it is highly trivial in TCustomGrid
, where it is defined as
function TCustomGrid.SelectCell(ACol, ARow: Longint): Boolean;
begin
Result := True;
end;
in TCustomDrawGrid
, we have
function TCustomDrawGrid.SelectCell(ACol, ARow: Longint): Boolean;
begin
Result := True;
if Assigned(FOnSelectCell) then FOnSelectCell(Self, ACol, ARow, Result);
end;
Hence, OnSelectCell
is called every time Row
or Col
is changed, as Skamradt wrote in a comment.
Yes, this event is called before the new cell is selected, but we have
FOnSelectCell: TSelectCellEvent;
where
type
TSelectCellEvent = procedure (Sender: TObject; ACol, ARow: Longint;
var CanSelect: Boolean) of object;
ACol
and ARow
contain the new "values-to-be". You can even disallow the change of selected cell by setting CanSelect
to false
. Consequently, there is no need to override anything.
(Also, you cannot override SetRow
because it is not virtual. It is very possible to override private and protected members, but only virtual methods can be overridden.)