Recent

Author Topic: [Solved] TShellTreeView  (Read 1009 times)

jcmontherock

  • Full Member
  • ***
  • Posts: 236
[Solved] TShellTreeView
« on: May 21, 2023, 06:12:11 pm »
I'm using TShellTreeView under Windows for selecting and working with some files and/or directories. When an entry has been selected I will get the path of this entry. I use for that: "ShellTreeView.items[n].GetTextPath". The result is not correct because the path delim char is '/' instead '\'. The path itself is ok.
Is it a bug or is it normal ?
« Last Edit: May 22, 2023, 11:38:30 am by jcmontherock »
Windows 11 UTF8-64 - Lazarus 3.2-64 - FPC 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: TShellTreeView
« Reply #1 on: May 21, 2023, 07:38:42 pm »
The recommended way to get the full path to a shelltree node is ShellTreeView.GetPathFromNode(ANode). GetTextPath is the method inherited from TCustomTreeView, and the items joined by this path not necessarily are elements of the file system. Imagine the hierarchy of classes in the LCL: then GetTextPath would return for TEdit: 'TObject/TPersistent/TComponent/TLCLComponent/TControl/TWinControl/TCustomEdit/TEdit' where '/' is some kind of path delimiter. In fact, in Laz main TCustomTreeView has a (protected) property PathDelimiter which is published in the new TShellTreeView to match the SysUtils.PathDelim, i.e. you can use GetTextPath and GetPathFromNode in the same way.

dsiders

  • Hero Member
  • *****
  • Posts: 1084
Re: TShellTreeView
« Reply #2 on: May 21, 2023, 07:59:00 pm »
I'm using TShellTreeView under Windows for selecting and working with some files and/or directories. When an entry has been selected I will get the path of this entry. I use for that: "ShellTreeView.items[n].GetTextPath". The result is not correct because the path delim char is '/' instead '\'. The path itself is ok.
Is it a bug or is it normal ?

I do not see that behavior using 2.3.0 (trunk). What version are you using?



Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: TShellTreeView
« Reply #3 on: May 21, 2023, 08:22:07 pm »
I do not see that behavior using 2.3.0 (trunk). What version are you using?
This is because in trunk the TCustomShellTreeView has a protected property PathDelimiter which is set in the TShellTreeView to the PathDelimiter of the file system.

jcmontherock

  • Full Member
  • ***
  • Posts: 236
Re: TShellTreeView
« Reply #4 on: May 22, 2023, 11:37:23 am »
Solved thanks a lot.

I replace: 
Code: Pascal  [Select][+][-]
  1. sPath := ShellTreeView.items[i].GetTextPath;
  2. sPath := sPath.Replace('/', '\', [rfReplaceAll, rfIgnoreCase]);
by:
Code: Pascal  [Select][+][-]
  1. sPath := ShellTreeView.GetPathFromNode(ShellTreeView.items[i]);

and it's work....

« Last Edit: May 22, 2023, 11:45:23 am by jcmontherock »
Windows 11 UTF8-64 - Lazarus 3.2-64 - FPC 3.2.2

 

TinyPortal © 2005-2018