Lazarus

Programming => LCL => Topic started by: wittbo on March 01, 2017, 12:28:58 am

Title: [SOLVED] DBGrid -DblClick fires CellClick too
Post by: wittbo on March 01, 2017, 12:28:58 am
I'm working with Lazarus 1.4.4. on macOS 10.10.5.

My application makes intensive use of DBGrids. Actually I found, that, when I double-click a cell/row, not only the OnDBlClick event is fired, but more than that, first a CellClick followed by a DblClick and then followed again by a CellClick event is fired. Since I have different handlers on CellClick and DblClick, this is very annoying.
Any idea?

-wittbo-
.
Title: Re: DBGrid -DblClick fires CellClick too
Post by: wp on March 01, 2017, 12:53:02 am
The same in Delphi Berlin, by the way...

In order to distinguish between conflicting single and double-clicks you can use a timer. Enable the timer in the MouseDown event. Set its duration a bit longer than the standard double-dlick time. In the OnTimer event of the timer, disable the timer again and process the code that you would have in the OnClick event. The old OnClick event is not needed any more.

I should not conceal the disadvantage: the application will feel a bit sluggish because the OnClick reaction is delayed by the duration of the timer.

Best would be to avoid such conflicting situations in the user interface.
Title: Re: DBGrid -DblClick fires CellClick too
Post by: wittbo on March 01, 2017, 07:03:52 am
The real problem was the CellClick after the preceding DblClick event. I solved it this way: in the DblClick handler I added a flag to remember this DblClick event. The first action in the CellClick event is to look at this flag. If the flag is set, then do nothing but to reset the flag, otherwise do normal handler action.
-wittbo-
TinyPortal © 2005-2018