Recent

Author Topic: NiceGrid freezes when resizing column by mouse  (Read 942 times)

chrv

  • Jr. Member
  • **
  • Posts: 68
NiceGrid freezes when resizing column by mouse
« on: September 23, 2023, 06:44:11 pm »
Hello everyone,

I'm using a TNiceGrid in my current project.
At runtime, when resizing a NiceGrid column with the mouse, my app freezes. It doesn't happend if changing column width by code.
Is this a known issue?

See attached code
Win32 Laz 2.0.12 FPC 3.2.0 AND Laz 3.4 FPC 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 12457
Re: NiceGrid freezes when resizing column by mouse
« Reply #1 on: September 23, 2023, 07:21:47 pm »
I confirm the issue, never saw it before. It happens in the show/hide scrollbar procedure.
« Last Edit: September 23, 2023, 07:44:09 pm by wp »

wp

  • Hero Member
  • *****
  • Posts: 12457
Re: NiceGrid freezes when resizing column by mouse
« Reply #2 on: September 23, 2023, 08:00:35 pm »
In TNiceGrid.Recalculate there are two calls to "SetScrollbar". The hang occurs aways when the provided offset (FHorzOffset, FVertOffset) is 0. The following modification fixes the issue for me:

Code: Pascal  [Select][+][-]
  1. procedure TNiceGrid.Recalculate;
  2. ...
  3.   FHorzOffset := Max(0, Min(FHorzOffset, FMaxHScroll));
  4.   FVertOffset := Max(0, Min(FVertOffset, FMaxVScroll));
  5.  
  6.   if FHorzOffset <> 0 then   // <--- ADDED
  7.     SetScrollBar(SB_HORZ, FMaxHScroll, FHorzOffset, SIF_POS or SIF_RANGE);
  8.   if FVertOffset <> 0 then   // <--- ADDED
  9.     SetScrollBar(SB_VERT, FMaxVScroll, FVertOffset, SIF_POS or SIF_RANGE);
  10.  
  11.   AllWidth := Min(ClientWidth, BodyWidth + FixedWidth);  
  12. ...

Please test, if this has any side-effects.

jamie

  • Hero Member
  • *****
  • Posts: 6733
Re: NiceGrid freezes when resizing column by mouse
« Reply #3 on: September 23, 2023, 08:26:40 pm »
shouldn't the SetScrollbar exit and do nothing on zero offset? I mean if that is a general function, it could cause issues for other code?
« Last Edit: September 23, 2023, 08:29:05 pm by jamie »
The only true wisdom is knowing you know nothing

chrv

  • Jr. Member
  • **
  • Posts: 68
Re: NiceGrid freezes when resizing column by mouse
« Reply #4 on: September 23, 2023, 10:32:07 pm »
@wp : It works for me. THANKS :D
Win32 Laz 2.0.12 FPC 3.2.0 AND Laz 3.4 FPC 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 12457
Re: NiceGrid freezes when resizing column by mouse
« Reply #5 on: September 23, 2023, 11:12:41 pm »
jamie made me think about it again. I don't know, maybe it's not correct. The issue is that Recalculate calls SetScrollbar and this triggers WMSize for whatever reason I don't understand. And WMSize has Recalculate again in its handler...

I think that most of these Windows-like messages may have been fixes in the early days of Delphi, but now in Lazarus they usually are not required any more and at places they are even harmful. Therefore I tested to remove the WMSize handler and to replace it by the Lazarus counterpart DoOnResize - and now the issue is gone (even without the "if FHorzOffset <> 0").

I also noticed that the mouse wheel is not working and fixed it in the same way (use DoMouseWheel rather than WMMouseWheel). And I tweaked mouse wheel support a bit: normal scrolling now is by 1 row, and when the CTRL key is pressed during scrolling it is by 5 rows.

To get the new version I'd recommend to download the snapshot zip file from https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/nicegrid/ (or to use SVN).

 

TinyPortal © 2005-2018