Recent

Author Topic: TCustomListview does not fire Click event?  (Read 2481 times)

d7_2_laz

  • Hero Member
  • *****
  • Posts: 512
TCustomListview does not fire Click event?
« on: March 09, 2021, 11:31:54 pm »
I'm bringing an old app from Delphi 7 to Lazarus 2.0.10 / Windows x64 only
and just noticed that within a component based on TCustomListView the Click event (on a listitem) does not fire. Trying with OnClick;= .... the same.
I couldn't believe that and looked into customlistview.inc and saw that the processing of the NM_CLICK notification is commented out (line 377).
Whereas in the Delphi 7 ComCtrls.pas  NM_Click is evaluated and remembered as a flag (FClicked := True;) that later is used for to distingiush that from drag and drop processing (being betwenn wm_lbuttundown/up). A simple hack here could badly interfere with Drag&Drop operations. I'd like to avoid such experiments.

I stopped my research for to ask, it this restriction (if if really should exist) is already known .... and what we can do here to precess a listview click event message in a component.
Lazarus 3.2  FPC 3.2.2 Win10 64bit

d7_2_laz

  • Hero Member
  • *****
  • Posts: 512
Re: TCustomListview does not fire Click event?
« Reply #1 on: March 09, 2021, 11:48:55 pm »
One day? That is is a joke?
I thought to process a click event within a custom listview item should be a very basic  request in 2021.
Lazarus 3.2  FPC 3.2.2 Win10 64bit

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: TCustomListview does not fire Click event?
« Reply #2 on: March 09, 2021, 11:53:52 pm »
I don't understand what you are talking about. Please run the attached project and see that the OnClick event indeed is fired.

Please provide a (simple) compilable example and demonstrate the issue.

Do not expect that the LCL works internally in exactly the same way as their VCL counterparts because LCL must support a variety of widgetsets while VCL only supports Windows.
« Last Edit: March 10, 2021, 12:09:37 am by wp »

d7_2_laz

  • Hero Member
  • *****
  • Posts: 512
Re: TCustomListview does not fire Click event?
« Reply #3 on: March 10, 2021, 12:14:26 am »
Hello wp, greetings!
i already did try a check against a regular listview and noticed that that one is processing the click indeed (picture).
I had thw issue with a customlistview based compo and simply was asking if it is supposed to work with that one too, I'd rather prefer it's my own error because it is so basic.

janie - you would say: yes i would need to reimplement parts of the old Delphi 7 ComCtrls.pas stuff again?  (TCustomListView.CNNotif), or, as another approach, using WM_Notify?
But would that help others when havnig the same prob?
Lazarus 3.2  FPC 3.2.2 Win10 64bit

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: TCustomListview does not fire Click event?
« Reply #4 on: March 10, 2021, 01:57:06 am »
It is still unclear what you want to achieve. An OnClick event that fires only when a listitem is clicked rather than clicking anywhere inside the listview? In this case override the Click method (there is no general DoClick) and check the result of the GetHitTestInfoAt function before calling inherited. (BTW, rather than destroying the inherited behaviour of the OnClick event I'd introduce a new event for this purpose such as "OnListItemClick").
« Last Edit: March 10, 2021, 02:02:08 am by wp »

d7_2_laz

  • Hero Member
  • *****
  • Posts: 512
Re: TCustomListview does not fire Click event?
« Reply #5 on: March 10, 2021, 02:13:55 am »
Thank you jamie and wp (wp: click onto a listitem caption, not into the non-selection area).

After a lot of investigation i found out that in fact i was wrong (it was hard for me to believe that the click could not be fetched in the customlistview in difference to the regular listview):

In fact the click had been eaten up (differently to D7 however!) by a BeginDrag operation in the MouseDown event. Those lines were guilty:
Code: Pascal  [Select][+][-]
  1.         if DragDetect(Handle, ClienttoScreen(Point(X, Y))) then
  2.            BeginDrag(True);

If i deactivate those lines, the click callback  is back. So i might have a problem elsewhere, but the original topic is a false assumption (because it's due to interference with DragDop). So i need to apologize! I was not aware of that when doing the post.
Of course it might be the case that those special measures in Delphi 7 comctrls.pas i mentioned in my OP had been the reason why i did not encounter that in Delphi.
Lazarus 3.2  FPC 3.2.2 Win10 64bit

 

TinyPortal © 2005-2018