Solved

Directory List - Doesn't show all folders?

Posted on 2007-11-15
7
2,802 Views
Last Modified: 2008-04-09
If you drop the Delphi directorylist component on a form, and look at the directories showing on your c drive ... it does not show all the same folders as Windows explorer.  For example go to your c:\documents and settings\ folder and on mine it shows 3 folders, while in windows explorer it shows 7. How do I get this to show everything?   You can look at the dirs in dos or in explorer, but the Delphi component doesn't show them all.   I use Delphi 2007 but in earlier versions the result is still the same.
0
Comment
Question by:jexd99
7 Comments
 
LVL 19

Expert Comment

by:MerijnB
ID: 20289200
are the directories hidden?
0
 
LVL 14

Expert Comment

by:SteveBay
ID: 20289576
TDirectoryListbox does not show items with hidden or system atrributes.

You could modify it by changing a line FileCtrl.pas in the Delphi\source\VCL Folder

Search for:
 â€œStatus := FindFirst(SlashSep(ParentDirectory, '*.*'), faDirectory, SearchRec);”
And change it to this:
 Status := FindFirst(SlashSep(ParentDirectory, '*.*'), faDirectory or faHidden or faSysFile, SearchRec);”

Steve
0
 
LVL 14

Expert Comment

by:SteveBay
ID: 20289602
.. without the weird characters:

change:
Status := FindFirst(SlashSep(ParentDirectory, '*.*'), faDirectory, SearchRec);

to:
Status := FindFirst(SlashSep(ParentDirectory, '*.*'), faDirectory or faHidden or faSysFile, SearchRec);
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:jexd99
ID: 20295675
I figured for sure that would fix it.... but it didn't.  Thats strange, those folders must have some attributes set differently, 3 of the folders are hidden but that still doesn't allow them to display even after I change the filectrl.pas.  The wierd thing is if I write my own routine just scrolling through the folders, it lists all of them no problem, but that directory listbox won't list them.
0
 

Author Comment

by:jexd99
ID: 20295767
Another odd thing is that I renamed filectrl.pas to 2filectrl.pas just to make sure it would get an error, and it didn't.  I don't see anywhere else where this file is getting read in from......  so I assume its pulling it in somewhere else or I should have received an error on this after recompiling.
0
 
LVL 10

Accepted Solution

by:
dinilud earned 50 total points
ID: 20296731
Try this
Unit1.dfm
==========
 
object Form1: TForm1
  Left = 142
  Top = 175
  Width = 431
  Height = 346
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object DirectoryListBox1: TDirectoryListBox
    Left = 0
    Top = 0
    Width = 423
    Height = 312
    Align = alClient
    ItemHeight = 16
    TabOrder = 0
  end
end
 
 
Unit1.pas
==========
 
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, FileCtrl;
 
type
  TDirectoryListBox=class(FileCtrl.TDirectoryListBox)
  protected
    procedure BuildList; override;
 
    function ReadDirectoryNames(const ParentDirectory: string;
                                           DirectoryList: TStringList): Integer;
  end;
 
 
 
  TForm1 = class(TForm)
    DirectoryListBox1: TDirectoryListBox;
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
function SlashSep(const Path, S: String): String;
begin
  if AnsiLastChar(Path)^ <> '\' then
    Result := Path + '\' + S
  else
    Result := Path + S;
end;
 
function TDirectoryListbox.ReadDirectoryNames(const ParentDirectory: string;
  DirectoryList: TStringList): Integer;
var
  Status: Integer;
  SearchRec: TSearchRec;
begin
  Result := 0;
  Status := FindFirst(SlashSep(ParentDirectory, '*.*'), faAnyFile xor faSysFile, SearchRec);
  try
    while Status = 0 do
    begin
      if (SearchRec.Attr and faDirectory = faDirectory) then
      begin
        if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
        begin
          DirectoryList.Add(SearchRec.Name);
          Inc(Result);
        end;
      end;
      Status := FindNext(SearchRec);
    end;
  finally
    FindClose(SearchRec);
  end;
end;
 
procedure TDirectoryListBox.BuildList;
var
  TempPath: string;
  DirName: string;
  IndentLevel, BackSlashPos: Integer;
  VolFlags: DWORD;
  I: Integer;
  Siblings: TStringList;
  NewSelect: Integer;
  Root: string;
  PPreserveCase,PCaseSensitive:PBoolean;
begin
  try
    Items.BeginUpdate;
    Items.Clear;
    IndentLevel := 0;
    Root := ExtractFileDrive(Directory)+'\';
    GetVolumeInformation(PChar(Root), nil, 0, nil, DWORD(i), VolFlags, nil, 0);
 
    pPreserveCase:=@PreserveCase;
    PCaseSensitive:=@CaseSensitive;
 
    pPreserveCase^ := VolFlags and (FS_CASE_IS_PRESERVED or FS_CASE_SENSITIVE) <> 0;
    PCaseSensitive^ := (VolFlags and FS_CASE_SENSITIVE) <> 0;
 
    if (Length(Root) >= 2) and (Root[2] = '\') then
    begin
      Items.AddObject(Root, OpenedBMP);
      Inc(IndentLevel);
      TempPath := Copy(Directory, Length(Root)+1, Length(Directory));
    end
    else
      TempPath := Directory;
    if (Length(TempPath) > 0) then
    begin
      if AnsiLastChar(TempPath)^ <> '\' then
      begin
        BackSlashPos := AnsiPos('\', TempPath);
        while BackSlashPos <> 0 do
        begin
          DirName := Copy(TempPath, 1, BackSlashPos - 1);
          if IndentLevel = 0 then DirName := DirName + '\';
          Delete(TempPath, 1, BackSlashPos);
          Items.AddObject(DirName, OpenedBMP);
          Inc(IndentLevel);
          BackSlashPos := AnsiPos('\', TempPath);
        end;
      end;
      Items.AddObject(TempPath, CurrentBMP);
    end;
    NewSelect := Items.Count - 1;
    Siblings := TStringList.Create;
    try
      Siblings.Sorted := True;
        { read all the dir names into Siblings }
      ReadDirectoryNames(Directory, Siblings);
      for i := 0 to Siblings.Count - 1 do
        Items.AddObject(Siblings[i], ClosedBMP);
    finally
      Siblings.Free;
    end;
  finally
    Items.EndUpdate;
  end;
  if HandleAllocated then
    ItemIndex := NewSelect;
end;
 
 
end.

Open in new window

0
 
LVL 14

Expert Comment

by:SteveBay
ID: 20297649
Check your library path. You may be getting the DCU rather than the PAS file. You may also need to BUILD rather  than just COMPILE because FileCtrl is not part of the project.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
my delphi exe application have  problem with windows explorer ! 12 84
Delphi XE10 Round Image 2 121
find a node in VST 2 68
How to renew a Delphi rad-studio licence? 5 63
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question