Working with the TfrShellTreeView Component in FastReport VCL

2025-04-22

FastReport isn’t just about report components—it has a lot more to offer! In particular, there are several components that you can use in your applications just like the other Delphi components, and we’re always adding more to the library. In this article, we’ll check out one of these: TfrShellTreeView.

This component is designed to display elements of the file system and is partially equivalent to components such as TDirectoryListBox, TDirectoryOutline in Delphi, and TShellTreeView in Lazarus. If you want to see how it looks without launching the IDE, that’s the "tree" you see on the left in the explorer window.

Program Window for Exploring the TfrShellTreeView Component

 

This component works great in Windows and Linux, for both Delphi and Lazarus. It doesn’t support FMX development.

TfrShellTreeView leverages a lot of operating system features. For instance, in Windows, you can treat zip archives like regular folders and even mess with their contents—extracting and adding files. Some features might not be available in Linux, depending on which version you’re running. But don’t worry: showing the tree and selecting elements will always work on any OS.

The main property of TfrShellTreeView that manages interaction with the operating system is OptionsShell.

Properties that Control Working with the Folder Tree

 

  • ContextMenu — specifies whether to show the system context menu for the selected file.
  • ShowFolder — this property displays folders.
  • ShowHidden — this property indicates whether hidden files will be visible or not.
  • ShowNonFolders — this property displays regular files (not folders).
  • TrackShellChanges — this property is designed to monitor changes in the file system. If you have any folder open in the component and it gets modified (for instance, if you copy a file into it), a new node representing that file will be automatically added to the component.

TfrShellTreeView supports a set of hotkeys specific to the standard file dialog or Explorer in Windows (Ctrl+С, Ctrl+V, Delete, etc.) with standard dialogs.

Also, the TfrShellTreeView component supports Drag&Drop of file system elements both within itself and from other (but not all) file managers. The OptionsBehavior.AllowDragDrop property is used to allow Drag&Drop operations. Dragging is carried out using operating system functions.

The remaining properties are similar to those in the TTreeView and TfrTreeView components. However, it is worth noting that they are grouped by type of use: OptionsBehavior, OptionsSelection, OptionsShell, OptionsView. This will allow you to quickly find the properties you need.

As mentioned above, the component is designed to display the computer’s file system. By default, the component is configured to display the root folder of your system: "Desktop" in Windows or "/" in Linux. However, the capabilities of the component are not limited to this. 

Let’s place the TfrShellTreeView component on the form and open its editor:

Component Editor

 

The TfrShellTreeView editor looks similar to the editors of the TTreeView and TfrTreeView components, but it has 2 new buttons:

  • New shell Root Item.
  • New shell Root SubItem.

As we can see in the editor screenshot, the component can contain:

  • Regular nodes, containing only text, such as "New simple item 1".
  • Nodes with a location in the file system, such as "This Computer", "Lazarus", "data". We will refer to such nodes as shell nodes.

Regular and child nodes are created and edited in the same way as in regular TreeViews.

Nodes that have a link to a file structure element are created using the "New shell Root Item" buttons. This will create a shell node of the same level as the current one. If you click on "New shell Root SubItem", a child shell node will be created in relation to the current node. Please note that you cannot create child nodes for a shell node, but you can for a regular node. 

Editing shell nodes comes down to specifying which folder the given node is linked to. You can set the binding to a folder using constants of the TfrRootNodes type. These constants define places such as the desktop, autostart, and so on. If you set the rfCustomPath constant, it becomes possible to add a path to the file system folder in the directory tree below. You can also set this path using the editing window located below the directory tree. For example, the screenshot below sets the path to the Lazarus folder located on drive C:\.

Editing a Shell Node

 

Like a regular TreeView, regular nodes of the component can be assigned icons. Shell nodes cannot be assigned icons; they use icons set in the operating system. For nodes, the icon index added in the ImageIndex property is actually used. The remaining icon indexes are not used. Also, due to the peculiarities of using the component, some other properties are not implemented. For example, there is no possibility of multiple selection of elements.

The most frequently used property is, of course, TfrShellTreeView.SelectedPath. If a shell node is selected, then this property contains the path to the folder to which this node points. Otherwise, this property is equal to an empty string.

In addition, working with the component is also available programmatically. You can add a regular (non-shell) node in the same ways as a regular TTreeView.

 frShellTreeView1.Items.Add(nil,Edit1.Text); 
//add a root node with text from Edit1


Adding a node to the currently selected node:

procedure TForm1.Button5Click(Sender: TObject);
var N:TfrShellTreeViewNode;
begin
 N:=(frShellTreeView1.Selected) as TfrShellTreeViewNode;
if N=nil then Exit;
 frShellTreeView1.Items.AddChild(N,Edit1.Text);
end;


Removing a node is also easy. For example, this is how the currently selected node is removed:

procedure TForm1.Button2Click(Sender: TObject);
var N:TfrShellTreeViewNode;
begin
 N:=(frShellTreeView1.Selected) as TfrShellTreeViewNode;
 if N=nil then exit;
 frShellTreeView1.Items.Delete(N);
end;

However, to remove a node, you can simply call its Free method.

Unfortunately, the component currently does not support generating events that occur when the file system folders associated with it change. The rest of the component’s functionality largely coincides with the standard TreeView.

In conclusion, FastReport is not only a tool for creating reports, but also a source of additional components that can be used in Delphi applications. TfrShellTreeView provides a convenient way to display file system elements and can be useful in various projects. The FastReport component library is constantly updated, which makes this tool even more attractive to developers.

VCL FastReport Interactivity Delphi RAD Studio
April 22, 2025

Working with XML and JSON Formats in FastScript

In this article, we will take a closer look at how to work with JSON and XML in FastReport, see what properties and methods they have, and build reports from code with scripts.
April 21, 2025

How RFID Tags Work in FastReport VCL

In this article, we'll check out how RFID tags work with the new TfrxDeviceCommand object in FastReport VCL with release 2025.2.
November 20, 2024

Localization and Language Switching in FastReport VCL

FastReport VCL supports 40 languages for interface localization and allows you to change the language on the fly through menus or code, without recompilation.
Fast Reports
  • 800-985-8986 (English, US)
  • +31 97 01025-8466 (English, EU)
  • +49 30 56837-3928 (German, DE)
  • +55 19 98147-8148 (Portuguese, BR)
  • info@fast-report.com
  • 66 Canal Center Plaza, Ste 505, Alexandria, VA 22314

© 1998-2025 Fast Reports Inc.