Using TFileFind To Populate A TTreeView with Folders

Post here your experiences, comments, suggestions, or bug reports regarding to the DELPHI AREA products. Not-matching topics will be moved or deleted.

Using TFileFind To Populate A TTreeView with Folders

by w2m » 02/04/10 00:26

I added a TTreeview to the filefind demo as an experiment to see if it is possible to fill a TTreeview with folders similar to ShellTreeview. I thought this would be a very fast way to do this because TFileFind is threaded.

The Treeview is populated with folders except the Treeview levels are not correct. How to detect that the folder name has changed to set the proper TTreeview level.

The code is as shown below.
What am I doing wrong when addtng the nodes?

Code: Select all
procedure TMainForm.FindFileFolderChange( Sender: TObject; const Folder: string; var IgnoreFolder: TFolderIgnore );
var
  Node: TTreenode;
begin
  Inc( Folders );
  StatusBar.SimpleText := Folder;
  if ( Treeview1.Items.Count = 0 ) then
  begin
    { Add the root node }
    with Treeview1.Items.AddFirst( nil, Folder ) do
      Selected := true;
  end
  else
  begin
    Node := Treeview1.Items.AddChild( Treeview1.Selected, Folder );
    Node.Selected := True;
  end;
  if not FindFile.Threaded then
    Application.ProcessMessages;
end;

procedure TMainForm.FindFileFileMatch( Sender: TObject; const FileInfo: TFileDetails );
var
  Node: TTreenode;
begin
  with FoundFiles.Items.Add do
  begin
    Caption := FileInfo.name;
    SubItems.Add( FileInfo.Location );
    if LongBool( FileInfo.Attributes and FILE_ATTRIBUTE_DIRECTORY ) then
    begin
      SubItems.Add( 'Folder' );
      if ( FileInfo.Attributes and faDirectory = faDirectory ) and ( FileInfo.name[ 1 ] <> '.' ) then
      begin
        Node := Treeview1.Items.Add( nil, FileInfo.name );
        Node.Selected := False;
      end;
    end
    else
      SubItems.Add( FormatFileSize( FileInfo.Size ) );
    SubItems.Add( DateTimeToStr( FileInfo.ModifiedTime ) );
  end;
  if not FindFile.Threaded then
    Application.ProcessMessages;
end;
w2m
w2m
Senior Member
Senior Member
 
Posts: 75
Joined: 08/03/03 19:11
Location: New York, USA

Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 0 guests