I'm trying to use the TShellTreeView component as a simple directory selector within a preferences form. Seems to work fine for what I'm doing EXCEPT when I set the Root directory as an explicit string it does not display the correct root directory name. It always seems to display the level 1 directory.
For example if I set
Root := 'c:\Program Files\Borland\Delphi 7';
then the root is displayed as Documents and Settings, but all the sub-directories of Delphi 7 are correctly displayed.
From my investigation the problem appears to be at \Demos\ShellControls\ShellCtrls.pas within procedure TCustomShellTreeView.CreateRoot:
Can anybody shed any light on what's going on and how to fix it?
I am running Delphi 7 Enterprise on Windows XP Pro.
For example if I set
Root := 'c:\Program Files\Borland\Delphi 7';
then the root is displayed as Documents and Settings, but all the sub-directories of Delphi 7 are correctly displayed.
From my investigation the problem appears to be at \Demos\ShellControls\ShellCtrls.pas within procedure TCustomShellTreeView.CreateRoot:
Code:
procedure TCustomShellTreeView.CreateRoot;
var
RootNode: TTreeNode;
ErrorMsg: string;
begin
if (csLoading in ComponentState) then Exit;
try
FRootFolder := CreateRootFolder(FRootFolder, FOldRoot, FRoot);
ErrorMsg := '';
except
on E : Exception do ErrorMsg := E.Message;
end;
if Assigned(FRootFolder) then
begin
FLoadingRoot := true;
try
if Items.Count > 0 then
ClearItems;
RootNode := Items.Add(nil, '');
with RootNode do
begin
Data := TShellFolder.Create(nil, FRootFolder.AbsoluteID, FRootFolder.ShellFolder);
[Blue]//This is the problem - Text is not set correctly[/Blue]
Text := GetDisplayName(DesktopShellFolder,
TShellFolder(Data).AbsoluteID,
SHGDN_NORMAL);
if FUseShellImages and not Assigned(Images) then
begin
RootNode.ImageIndex := GetShellImage(TShellFolder(RootNode.Data).AbsoluteID, False, False);
RootNode.SelectedIndex := GetShellImage(TShellFolder(RootNode.Data).AbsoluteID, False, True);
end;
RootNode.HasChildren := TShellFolder(RootNode.Data).SubFolders;
end;
RootNode.Expand(False);
Selected := RootNode;
finally
FLoadingRoot := False;
end;
end;
if ErrorMsg <> '' then
Raise Exception.Create( ErrorMsg );
end;
I am running Delphi 7 Enterprise on Windows XP Pro.