Search code examples
shelldelphiwinapidelphi-11-alexandria

How to extract the folder path from PItemIDList parameter in TRzShellTree.OnAddItem event handler?


In a 32-bit VCL Application in Windows 10 in Delphi 11 Alexandria, I have a TRzShellTree control (by Ray Konopka from the Konopka Signature VCL Controls 7.0 available in GetIt):

object RzShellTree1: TRzShellTree
  Left = 0
  Top = 41
  Width = 201
  Height = 428
  Align = alLeft
  BaseFolder.Pidl = {
    004301000014001F50E04FD020EA3A6910A2D808002B30309D19002F433A5C00
    00000000000000000000000000000000000054003100000000003D5465581100
    44454C50484900003E0009000400EFBE1423F90E42549B502E00000000930F00
    000001000000000000000000000000000000DFED4800440045004C0050004800
    4900000016005A0031000000000042546956100053757065724D525500004200
    09000400EFBE2154F655425469562E000000210A000000004B00000000000000
    0000000000000000C43CDA00530075007000650072004D005200550000001800
    660031000000000042546F56100050524F4A45437E3100004E0009000400EFBE
    4254695642546F562E00000043EB0A0000000B00000000000000000000000000
    000008E22E00500052004F004A004500430054002000470052004F0055005000
    5300000018000000}
  Indent = 19
  ReadOnly = True
  SelectionPen.Color = clBtnShadow
  TabOrder = 0
  OnChange = RzShellTree1Change
  OnDragOver = RzShellTree1DragOver
end

...where in the TRzShellTree.OnAddItem event handler I need to get the PATH of each added folder:

procedure TformMain.RzShellTreeGroupsAddItem(Sender: TObject; ParentIShf: IShellFolder_NRC; ParentAbsIdList, ItemRelIdList: PItemIDList; Attribs: Integer; var AllowAdd: LongBool);
begin
  // How to get the PATH of the added folder?
end;

I assume this could be done by extracting the path from the ItemRelIdList: PItemIDList parameter. But I don't know how to do that.


Solution

  • The RzShellUtils unit contains a number of helpful functions to deal with this sort of thing. In particular,

    uses
      RzShellUtils;
    
    procedure TForm13.RzShellTree1AddItem(Sender: TObject; ParentIShf: IShellFolder_NRC; ParentAbsIdList,
      ItemRelIdList: PItemIDList; Attribs: Integer; var AllowAdd: LongBool);
    var
      S: string;
    begin
      S := ShellGetPathFromIdList( ItemRelIdList );
      CodeSite.Send( 'S', S );
    end;