1. Technology

Deactivating the TShellTreeView Delphi Control - Faking the Active Property

Set ObjectTypes to [] (empty set) to fake "Active" := false

By

Delphi's TShellTreeView component displays a hierarchical tree view of the system's shell folders and files.

The ObjectTypes property of the ShellTreeView determines what shell elements are displayed by the control. The ObjectType is a set type property defined as:

TShellObjectType = (otFolders, otNonFolders, otHidden);
TShellObjectTypes = set of TShellObjectType;
By default, only otFolders is included in ObjectTypes - meaning that a ShellTreeView will only display folders.

Including the otNonFolders value would result in files to be included in the display (more correctly: non-folders). otHidden includes hidden items.

When you include otNonFolders (and otHidden) it will take some time for the component to display its content.

Active property?

I have an application using TShellTreeView with otFolders and otNonFolders set for ObjectTypes. The actual shell tree is, by design, not visible, and is only presented to the user when actually needed.

When the form hosting the shelltreeview is created, the TShellTreeView will read the shell structure and populate the tree. Note that the component is not visible by default - therefore not "needed" at form creation. The process of enumerating the shell as done by the component takes some time (a few seconds) and it appears as if the application is frozen.

Unfortunately, there's no Active property one can set to false to force the component NOT to display its contents.

Fortunately, there's the ObjectTypes property you can set to an empty set:

ShellTreeView1.ObjectTypes := []; //display nothing
By setting the ObjectTypes property to an empty set value you can fake a non - existing Active property.

As previously said, when the form is created the shelltreeview, in my application, is not visible - therefore I do not need it to display any content (folders / files / network locations, ...).

When a user wants to use the shell tree view I will simply set the ObjectTypes property to a "non-empty" value - thus having the control display shell elements:

if (shellTreeView.ObjectTypes = []) then
begin
//activate the control
shellTreeView.ObjectTypes := [otFolders, otNonFolders];
end;
Yes, it does take some time for the control to refresh (display shell elements) but this time the user is aware of what is happening.

Delphi tips navigator:
» Store/Load RTF Resource File
« MultiSelect in TShellListView

  1. About.com
  2. Technology
  3. Delphi
  4. Using VCL Components
  5. Deactivating the TShellTreeView Delphi Control - Faking the Active (Nonexisting) Property

©2014 About.com. All rights reserved.