TShellListView empty space artifact after setting .Mask lazarus / 31-LCL ---------------------------------------------------------------------- anse · 2025-12-01 16:13 Hi all, Windows 11, Lazarus 4.2, FPC 3.2.2 I have a TShellListView and a combobox where I can select the file mask for it, either *.* or *.txt When i scroll down and select a file, then set a different mask, the list shows an empty space artifact at the top scoll position. It disappears aftert scrolling up and down several times. On a quick test with Ubuntu gtk2, that issue does not appear. The list has only default properties set. Codewise I do nothing really special: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.comboMaskChange(Sender: TObject);begin  ShellListView1.Root:='c:\temp';  ShellListView1.Mask:=comboMask.Text;end;  The artifact shows like the attached image. I already tried to wrap the two lines in .Begin/EndUpdate, added a .Refresh and a .Repaint - nothing helped here. ---------------------------------------------------------------------- wp · 2025-12-01 19:15 I can reproduce this with these steps: - Set ShellListView.Root to some directory which has more items than can be shown in the unscrolled listview. - When the directory is shown, scroll down by at least 1 item. - Change the mask to any filter. Even *.* is working, and even when the test program started with this same mask. --> The screen is empty When I now drag the window vertically out of the screen as much as possible and drag it back the missing items are back (at least those which had been scrolled below the screen bottom)! ---------------------------------------------------------------------- jamie · 2025-12-02 00:07 I can't get that to fail on my Win10 machine however, looking at the sources, it tells me that a list population is done twice, one after the other by setting the root or mask and in this case, its scanning twice not once.  a Lot of going on here in that code so its hard to say but maybe a file caching issue with Win11 when collection items. the only thing I can think of at this time is maybe the Message queue to refresh the ListView is over writing the last one before it gets a chance to process. Windows does put low priority on some Gui stuff. Jamie ---------------------------------------------------------------------- jamie · 2025-12-02 00:18 I think a method needs to be added to the control, for example "SetMaskAndRooT" Where the mask or Root property gets set at it's lowest level but does not clear anything in the control yet then when setting the other item it would then do list update so this only happens once! Jamie. ---------------------------------------------------------------------- jamie · 2025-12-02 03:03 Seems to me an issue with the scrollbars not getting reset maybe.. Anyways, I tried it with ssAutoBoth in the OI, I played with it and I didn't see the effects afterwards. I also added a method to the class locally. You can look at it where I first set both Root and mask strings without calling the Setter property, then Build the list, this way it gets done once. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Windows,Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ShellCtrls, StdCtrls; type { TShellListView } TShellListView = Class(ShellCtrls.TShellListView)  Procedure SetMaskAndRoot(aMask,Aroot:String);end;   { TForm1 }   TForm1 = class(TForm)    ComboBox1: TComboBox;    ShellListView1: TShellListView;    procedure ComboBox1Change(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TShellListView } procedure TShellListView.SetMaskAndRoot(aMask, Aroot: String);Type  TS = ^String;Var  S:TS;begin  S := @Mask;  S^:=aMask;  S := @Root;  S^ := ARoot;  clear;  Items.Clear;  PopulateWithRoot;end; { TForm1 } procedure TForm1.ComboBox1Change(Sender: TObject);begin  {Set your Scrollbars in the OI to ssAutoBoth}  ShellListView1.SetMaskAndRoot(com bobox1.Text,'c:\Lazarus64');end; end.   You can implement the local hack I did in your project. It must be done in the same unit you are using the control in. I think It loads faster this way, at least that is what I see. Jamie ---------------------------------------------------------------------- anse · 2025-12-02 05:25 Hey Jamie, thanks a lot for your quick tests. I did it exactly like you mentioned above. But that SetMaskAndRoot works exactly like before, with creating the empty space after the second call to it. Also played with ScrollBars in the OI, and even I see other issues with ssHorizontal and ssVertical, showing the other/unwanted scrollbar as well. Only ssNone seems to not create that space, but that's probably normal And yes, the list, or especially the scrollbars flash a few times, as if it was updated more than once. Other ideas? ---------------------------------------------------------------------- wp · 2025-12-02 10:52 A workaround is to force scrolling to the top before setting the Mask: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ComboBox1Change(Sender: TObject);begin  if ShellListView1.Items.Count > 0 then    ShellListView1.Items[0].MakeVisible(true);  ShellListView1.Mask := ComboBox1.Text;end; ---------------------------------------------------------------------- anse · 2025-12-02 16:57 Yea definitely a workaround. But that does not work when the filtered list after setting the Mask has only a few items and no scrollbar is visible. I tend to report it as an issue on gitlab.com/groups/freepascal.org/lazarus/ ---------------------------------------------------------------------- BrunoK · 2025-12-02 19:03 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ComboBox1Change(Sender: TObject);begin  ShellListView1.Mask := ComboBox1.Text;  if ShellListView1.Items.Count > 0 then    ShellListView1.Items[0].MakeVisible(true);end;I would suggest first apply mask so items are updated ---------------------------------------------------------------------- anse · 2025-12-02 19:28 Ah, now I get the point of wp's workaround: it has to scroll to top before setting Mask or Root. The empty space only appears afterwards, when the scroll bar was not at the top position before. I think I mixed that up today. So, yes, wp's workaround indeed works. Thanks a lot! ---------------------------------------------------------------------- wp · 2025-12-02 23:41 Yes, the idea was based on your observation that scrolling is necessary for the bug to occur - therefore: scroll the listview back to the top before setting the mask. The only problem was that I wrote my code in a bit misleading way. Better: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     procedure TForm1.ComboBox1Change(Sender: TObject);    begin      if ShellListView1.Items.Count > 0 then   // nothing to do when there are no items...      begin        ShellListView1.Items[0].MakeVisible(true);        ShellListView1.Mask := ComboBox1.Text;      end;    end; But of course, this is just a workaround. Something is missing in the win32/64 widgetset code which causes this behaviour. I would have thought that the issue itself is already in TCustomListView because TShellListview does not touch scrolling at all. But the attached test project demonstrates that this is not true: the Listview works correctly when it is populated by some given strings, scrolled down, then re-populated with the same strings but filtered such that only strings beginning with 'a' are accepted - the listview displays the filtered list correctly, no blank part. Or did is miss something when writing this project? ---------------------------------------------------------------------- jamie · 2025-12-03 00:05 Even with the workaround, it still does it here but not unless you change the listing mask a few times and keep refreshing it. At first start, it all works but after a while it starts doing it again through mask changes or root changes. It appears to me there is some sort of resource leak that is building up. are all the Icon handles property disposed of from the system when clearing the list? Jamie ---------------------------------------------------------------------- jamie · 2025-12-03 01:08 Yes, there is something wrong with the release of resources each time the list gets updated. I reran that test app to watch it slowly degrade to the point where it no longer showed any icons. I think a RecreateWindow needs to be done each time the list if redone to release all the icons assigned to the control. Currently, that test app no longer shows icons. Most likely need to restart the system. Definitely a resource leak. Jamie ---------------------------------------------------------------------- anse · 2025-12-03 10:04 Quote from: wp on December 03, 2025, 12:41:26 am... the listview displays the filtered list correctly, no blank part. Or did is miss something when writing this project? No empty space with your project here as well. On Windows 11 by the way. Supports your assumption that TShellListView owns the empty space issue, not TCustomListView. I also assigned an empty image list so no icons are displayed. Which makes no difference, the empty space still is there. So I assume the icons have no relevance for the issue. ---------------------------------------------------------------------- jamie · 2025-12-03 10:50 I suspect there is an issue with the widget for 64 bit because I just ran a test in 32 bit and all works as it should with the system icons showing and it does not seem to have any side effects after several iterations of reloading the list with different mask and roots.  You don't need have any of the local icons images assigned for the icons to appear, they appear regardless if things are working, maybe.  This reminds me of bad pointers cause by bad implementation of the windows file for example.   jamie ---------------------------------------------------------------------- BrunoK · 2025-12-03 15:52 Lazarus Trunk, Fpc 3.2.2 I modified a bit the project and now I can't reproduce the problem and that surprises me because there is nothing indicating what could have made things work. And an other point is that the project does not work well on linux. ---------------------------------------------------------------------- wp · 2025-12-03 18:42 Strange... Ran my own test project for comparison - it shows the issue, your's doesn't. I thought it might be the btnChDirClick in FormCreate, but commenting it out makes no difference. Ran your project under Linux with qt5 qt6, gtk3 (these x11) and with gtk2 (wayland). Qt5 and qt6 are correct, gtk2 and gtk3 display only the Type column - is this what you are meaning with "does not work well on Linux"? This is because the other columns have a width of 1 px only. Found out that this originates in "AdjustColWidths" which gets zero ListView's ClientWidth in gtk2/gtk3 when it is called. Added another call in TShellListView.Loaded, and this fixes the issue. ---------------------------------------------------------------------- BrunoK · 2025-12-03 19:42 Quote from: wp on December 03, 2025, 07:42:12 pmStrange... Ran my own test project for comparison - it shows the issue, your's doesn't. I thought it might be the btnChDirClick in FormCreate, but commenting it out makes no difference. May be it is that the original poster had a change of mask and a change of root in the same  control click. But I haven't been able to see why that should affect things. I tried to modify win32callback.inc and add a WM_SETREDRAW: DoMsgRedraw; that calls ListView_EnsureVisible but if I remember, it successfully displayed the contents but the icons did also disappear after a few calls. Quote and with gtk2 ...  display only the Type column - is this what you are meaning with "does not work well on Linux"? Yes Glad that you saw the same issues because sometimes I get the feeling of being lost. ---------------------------------------------------------------------- jamie · 2025-12-04 00:19 I have been studying the code in the Win32wsshellctrls and I don't think the use of the ListView_GetImageList and set_ImageList is correct?  In code, the list view image list is created when it is detected that it does not exists, so the current image index that was returned from the system per current filename introduced will trigger a creation of the list, and add that one image from the system image handle to it.  But I only see one image being added so something is strange here.  Normally you create an image list, add all the images to that list while enumerating, free each handle as you go, and in the end, assign that image list to the ListView_SetImageList and now you have an attached list.  On top of that, when refreshing the list via a different ext for example, I don't think that list ever gets reloaded with new icons, because it already exists with the prior one, this can lead the list to not having the indexed item in it and do all sorts of nice things.  I would thing the list needs to be purged between refreshes.  Maybe I am overloading something, but this isn't working from what I can see. Please look here at an C example. https://learn.microsoft.com/en-us/windows/win32/controls/add-list- view-image-lists Jamie ---------------------------------------------------------------------- wp · 2025-12-04 10:17 Quote from: jamie on December 04, 2025, 01:19:16 am In code, the list view image list is created when it is detected that it does not exists, so the current image index that was returned from the system per current filename introduced will trigger a creation of the list, and add that one image from the system image handle to it. Created? I would not call it like that. It is a system imagelist which exists independently of the ListView. As far as I understand, the code in TWin32WSCustomShellListView.GetBuiltInImageIndex only assigns the handle of this system imagelist to the ListView (via ListView_SetImageList). Quote from: jamie on December 04, 2025, 01:19:16 am But I only see one image being added so something is strange here. No image is "added" to this imagelist. SHGetFileInfoW only gets some file info record which contains the image index for the given file in that system imagelist. And the image index is all the Listview needs to display an icon for that file. And of course, this functions is called again and again during the listview population phase for each file added. Quote from: jamie on December 04, 2025, 01:19:16 am Normally you create an image list, add all the images to that list while enumerating, free each handle as you go, and in the end, assign that image list to the ListView_SetImageList and now you have an attached list. Normally, yes. But not here. Simply speaking: the function just finds the image index for a given file in an system-wide existing imagelist. There were several discussions about this topic; https://forum.lazarus.freepascal.org/index.php?topic=31625.0 is one of them. ---------------------------------------------------------------------- jamie · 2025-12-04 11:20 Okay I'm going to drop out of this thread because it's obviously it's not going anywhere for me I'll just not use that control.  thank you very much your hard work. Jamie.