Hi,

Attached is another patch that fixes my previous issues as well.

Fixes
-----------------------------
* Click event fires when Col property is set
* Click event fires when Row property is set
* Click event fires when navigation keys (left, right, up, down,
PgUp, PgDn, Begin, End) are pressed.

Based on my previous patch the following two issue are also fixed now.
-----------------------------
 * Click event fires when navigation keys are pressed, but the
selection doesn't (can't) change. Like pressing the up arrow while the
selection is already in the top/left corner. Click shouldn't fire in
this case.
* Click fires twice when selecting a range


As for the Options setting to paint the focused cell. I now agree with
you that the default is correct (even for Delphi compatibility) and if
you need to see the focused cell, the option is available to you.

Probably, I didn't see in your patch that you have overriden click method,

I don't understand why I need to override the Click method? Could you explain.

that might explain the increased number of clicks, but without seeing the
original patch and test code it's difficult to guess the cause.

The test code is very simple. A form with a TStringGrid, a TMemo and
two TEdit's to set the Row and Col values. The TMemo is used to
displays when the Click event has fired.  I implemented a
TStringGrid.OnClick event handler that writes "Click" to the Memo.

I did this with Delphi 7 and Lazarus and compared the output to the
Memo.  My user actions are pressing navigation keys, selecting cells
with the mouse, selecting ranges with the mouse and setting Col and
Row with the two TEdit's.  Are there other user actions I forgot which
will cause the OnClick to fire?


--
Graeme Geldenhuys

There's no place like S34° 03.168'  E018° 49.342'
Index: lcl/grids.pas
===================================================================
--- lcl/grids.pas	(revision 10980)
+++ lcl/grids.pas	(working copy)
@@ -2006,12 +2006,14 @@
 begin
   if AValue=FCol then Exit;
   MoveExtend(False, AValue, FRow);
+  Click;
 end;
 
 procedure TCustomGrid.SetRow(AValue: Integer);
 begin
   if AValue=FRow then Exit;
   MoveExtend(False, FCol, AValue);
+  Click;
 end;
 
 procedure TCustomGrid.Sort(ColSorting: Boolean; index, IndxFrom, IndxTo: Integer);
@@ -4638,8 +4640,11 @@
     FGCache.TLColOff:=0;
     FGCache.TLRowOff:=0;
     SelectActive:=Sh;
-    MoveNextSelectable(Rel, aCol, aRow);
-    Key:=0;
+    if MoveNextSelectable(Rel, aCol, aRow) then
+    begin
+      Key := 0;
+      Click;
+    end;
   end;
 begin
   {$ifdef dbgGrid}DebugLn('Grid.KeyDown INIT Key=',IntToStr(Key));{$endif}

Reply via email to