Solved

Directory List - Doesn't show all folders?

Posted on 2007-11-15
7
2,805 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Syntax Check Delphi Seattle IOS app without MAC ? 1 106
code issue 8 157
How to load 2 images in same column in Delphi 2 57
DBCtrlGrid, Delphi, Scroll 7 26
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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 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