1. Home
  2. Computing & Technology
  3. Delphi Programming
Shell Controls: Delphi's Hidden Gems
How to create a reasonable Delphi facsimile of the Windows explorer, all without writing a single line of code.
 More of this Feature
• Part 2: Regular Expression Filename Filtering
 Join the Discussion
"Post your views, comments, questions and doubts to this article."
Discuss!
 Related Resources
• Monitoring Shell Changes
• Windows API

Article submitted by: George Merriman for the Delphi Programming Quickies Contest.

Delphi's shell controls are hidden gems: they are hard to find and lack any meaningful documentation. I discovered them, almost by accident, while working on a recent project. I hope that this short account of what I discovered will prove to be both interesting and useful for you.

   Shell Controls
The first problem with using these components is to find them. They appear in the list of installed packages as "Shell Control Property and Component Editors", not what I would call an obvious description. You can add them to your palette by going to Components/Add Packages from the Delphi main menu and then scrolling down to check the appropriate box in the Design Packages list. You should now find the four shell controls on the Samples tab of your component palette: ShellTreeView, ShellComboBox, ShellListView, and ShellChangeNotifier. The source for these files is in ShellCtrls.pas in the Demos\ShellControls directory in the Delphi directory tree.

Due to the lack of documentation, the only way I could figure out how these components work was to create a quick-and-dirty test harness. It consists of some Panel controls, a Splitter, and one each of the shell controls from the Samples palette, as shown in the screen shot below. There is nothing unusual going on with the form layout, so I want to move on to the interesting bits. You can check out the details in the Delphi 7 project files included in the download. Be sure to check out the Align property of the controls.

Delphi Shell Controls

You will notice that the Object Inspector shows some properties, listed in red, that allow you to interconnect the shell controls at the click of a button. If you run the app without setting these, the controls work individually, but don't work together as they do in Windows Explorer. If, however, you use Object Inspector to set the ShellTreeView property of the ShellListView to point to your tree view, and the ShellComboBox property of the tree view to your ShellComboBox, you will see these three controls start working together.

Click, set, "connect"
Object Inspector conveniently offers links to the other controls in drop-down lists, so it is hard to go wrong. You will also see that, as you set up a link to a control, a link is automatically set up in the linked control, so that the interactions are reciprocal. While you are at it, have a look around at the other properties of these components. Some familiar ones are inherited from the underlying standard VCL controls; others, such as ObjectType and Root, are new. Play around a bit and see what they do.

On ShellChangeNotifier
So far, I haven't said anything about the ShellChangeNotifier control. This non-visual component provides simplified access to the native Win32 file system change monitoring facility. It turns out that the AutoRefresh property of the tree and list view controls provide this functionality automatically by creating an instance of the ShellChangeNotifier behind the scenes. I discovered this fact by poking around in the source code in ShellCtrls.pas. I urge you to look at this code for yourself-I know you will learn a lot.

Now we have a reasonable Delphi facsimile of the Windows explorer, all without writing a single line of code. It doesn't do much, but you can right-click and double click the items in the tree and list views and get the expected results. The real value of our little project is that we can use it as the basis for further work, which is exactly what I intend to do in my next article.

Explore Delphi Programming

More from About.com

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. Shell Controls: Delphi's Hidden Gems

©2008 About.com, a part of The New York Times Company.

All rights reserved.