..retrieve the path of the selected file in a TShellListView?

Author: Thomas Stutz

Category: VCL

// These two solutions don't work:
// Diese zwei Lösungen funktionieren nicht wie erwartet:

{ 1. }

Label1.Caption := TShellFolder(ShellListView1.RootFolder).PathName;

{ 2. }

var
  
p: TPoint;
  item: TListItem;
begin
  
GetCursorPos(p);
  p := ShellListView1.ScreenToClient(p);
  item := ShellListView1.GetItemAt(p.X, p.Y);
  if item <> nil then
    
Caption := item.Caption
end;


// But this works:
// Aber so geht's:

Label1.Caption := ShellListView1.Folders[ShellListView1.ItemIndex].PathName

{**************************************************************}

{
  To retrieve full paths to each file selected files:
}

var
  
path: string;
begin
  for 
i:=0 to ShellListView1.SelCount-1 do
  begin
    
path := ShellListView1.Folders[ShellListView1.GetNextItem(ShellListView1.Selected,
              sdAll,[isSelected]).Index+i-1].PathName;
    // ...
  
end;
end

 

printed from
www.swissdelphicenter.ch
developers knowledge base