Recent

Author Topic: [SOLVED] Treeview, possible to late set Node.HasChildren (plus sign)?  (Read 18624 times)

d7_2_laz

  • Full Member
  • ***
  • Posts: 198
Yes, OnHasChildren is published.
"Root" stayed empty, for to start with the drives.
"Within the IDE" did mean, not the demo is used, but the thing is newly created in the IDE by placing the control etc. . -  Running the app within the IDE, or by clicking the executable, didn't make a difference.
Maybe we would can shorten it if you try to run my "mini-project", only containing the shelltreeview, and see, if you result in more than one folder beyond C:\. ?
If yes, it's eighter a mistake in my exchanged files (I'll add them here, maybe could a diff against yours for to assure), or something else in the envrionment.

wp

  • Hero Member
  • *****
  • Posts: 8897
I see all drives - see attached screenshot.

Your ShellCtrls is lacking the loop over the found files in TCustomShellTreeView.PopulateTreeNodeWithFiles. Here is the correct version (with the old commented stuff removed):
Code: Pascal  [Select][+][-]
  1. { Returns true if at least one item was added, false otherwise }
  2. function TCustomShellTreeView.PopulateTreeNodeWithFiles(
  3.   ANode: TTreeNode; ANodePath: string): Boolean;
  4. var
  5.   i: Integer;
  6.   Files: TStringList;
  7.   NewNode: TTreeNode;
  8.   CanAdd: Boolean;
  9. begin
  10.   Result := False;
  11.   // avoids crashes in the IDE by not populating during design
  12.   if (csDesigning in ComponentState) then Exit;
  13.  
  14.   Files := TStringList.Create;
  15.   Items.BeginUpdate;
  16.   try
  17.     Files.OwnsObjects := True;
  18.     GetFilesInDir(ANodePath, AllFilesMask, FObjectTypes, Files, FFileSortType);
  19.     Result := Files.Count > 0;
  20.  
  21.     for i := 0 to Files.Count - 1 do
  22.     begin
  23.       CanAdd := True;
  24.       with TFileItem(Files.Objects[i]) do DoAddItem(FBasePath, FileInfo, CanAdd);
  25.       if CanAdd then
  26.       begin
  27.         NewNode := Items.AddChildObject(ANode, Files[i], nil);
  28.         TShellTreeNode(NewNode).FFileInfo := TFileItem(Files.Objects[i]).FileInfo;
  29.         TShellTreeNode(NewNode).SetBasePath(TFileItem(Files.Objects[i]).FBasePath);
  30.       end;
  31.     end;
  32.   finally
  33.     Files.Free;
  34.     Items.EndUpdate;
  35.   end;
  36. end;
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

d7_2_laz

  • Full Member
  • ***
  • Posts: 198
Yes, right, the missing line gots a victim of a misplaced edit action late evening  :o
- thanks!
Much better now, even heavy populated folders are opened lightning fast  :)  :)
So i hope that for you it had been a well spent time though.

The second good news is: the change is directly usable by the shellview demo mentioned too, Which benefits without further changes.
-
One little side node (only an observation): surprisingly the first open is faster than subsequent ones (folder expand -> collapse --> expand); not severe at all, but a bit curious.
-
For me it's now the task to retransport the principle of the ShellControls changes into my own app, that is working generically without the ShellControls ..
« Last Edit: July 15, 2021, 10:08:30 am by d7_2_laz »

d7_2_laz

  • Full Member
  • ***
  • Posts: 198
The outcome is: the pinciple is nicely applicable to apps too that don't use the ShellControls itself: it works very fine and fast!
Tremendous speedup .. perfectly solved!

wp

  • Hero Member
  • *****
  • Posts: 8897
Re: [SOLVED] Treeview, possible to late set Node.HasChildren (plus sign)?
« Reply #34 on: July 15, 2021, 10:58:18 am »
Committed to trunk and requested back-porting to v2.2RC2.

The largest part of the slow-down when a heavily populated node is opened a second time is due to a missing BeginUpdate/EndUpdate pair around Node.DeleteChildren in the ShellTreeView's CanExpand method (about 20 s for c:\Windows\WinSxS) - but this was already included in the pre-version that you used. With BeginUpdate/EndUpdate the delay shortens to about 1 second. I checked the involved procedures and found nothing suspicious. The problem seems to be that all subnodes have to be iterated when their parent node is closed.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

d7_2_laz

  • Full Member
  • ***
  • Posts: 198
Re: [SOLVED] Treeview, possible to late set Node.HasChildren (plus sign)?
« Reply #35 on: July 15, 2021, 02:26:03 pm »
Had guessed such a direction, as after transfer of the change to my app, here the effect did _not_ occur.
I had already noticed this difference in CanExpand, but had not been sure if it was directly related to your recent change / this specific topic.

Btw, it is good to see that the fix from the thread "Trouble with CustomTreeView (OnExpand)" (SIGSEGV at CanExpand when inside Begin-/End-Update) indeed is part of 2.2 - the problem did not reoccur here.

A lot of thanks for having involved so deeply! Great experience.

 

TinyPortal © 2005-2018