I need to know when the row/column property of a grid was changed in order to do some processing.
In TStringGrid Row property is
property Row: Longint read FCurrent.Y write SetRow;
But, unfortunately I cannot override the SetRow as it is private. SelectCell is not private BUT it is called BEFORE the new column and row attribute is set. The only solution will be to replace all calls to Row property with my own property
property MyRow: Longint read Row write SetMyRow;
but it is not the most elegant solution.
Any ideas?
Delphi 7, Win 7 32 bit
I just had a look at the source of
TStringGrid. TheRowproperty is inherited fromTCustomGrid(viaTDrawGridandTCustomDrawGrid), where it is defined asas you say.
SetRowcallsFocusCellwhichs callsMoveCurrent. This one callsSelectCell. This is a virtual function, and although it is highly trivial inTCustomGrid, where it is defined asin
TCustomDrawGrid, we haveHence,
OnSelectCellis called every timeRoworColis changed, as Skamradt wrote in a comment.Yes, this event is called before the new cell is selected, but we have
where
AColandARowcontain the new “values-to-be”. You can even disallow the change of selected cell by settingCanSelecttofalse. Consequently, there is no need to override anything.(Also, you cannot override
SetRowbecause it is not virtual. It is very possible to override private and protected members, but only virtual methods can be overridden.)