Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Root name displayed byTShellViewList

Status
Not open for further replies.

bobbie100

Programmer
Aug 29, 2003
64
GB
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:
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;
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top