DelphiDabbler Shell Folders Demo
This project is provided with the DelphiDabbler Shell Folders unit to demonstrate
how to use some of the code in the unit.
Installing the Demo Project
The demo project is provided in the same zip file as the Shell Folders unit.
Follow the installation instructions supplied with the zip file. Ensure that
the component contained in the shell folders unit are installed before attempting
to compile the demo project. The demo was created with Delphi 4.
Overview
The demo program exercises much of the main code in PJShellFolders.pas
.
On starting the program displays information about each of the supported special
shell folders in the main part of the window. This information is:
- ID: the symbolic constant associated with the folder
- Display name: the display name of the folder (or <not supported> if
the folder is not supported by the underlying operating system).
- Folder path: the path to the folder in the file system. If the folder is
not part of the physical file system, i.e. is virtual, then <virtual folder>
is displayed. No entry is preset for unsupported folders.
Below the main display are several controls:
- Browse selected folder button: Clicking this button displays the
Browse for Folder dialog box with the selected special folder as the root
in the display. Click the button to experiment with the dialog, the behaviour
of which changes according to the state of some other controls. If the selected
folder is not supported by the operating system the button is displayed. The
dialog can also be displayed by double clicking the folder's entry in the
display. Note that the dialog box is customised with an extra text box that
appears between the tree view and the buttons and displays the symbolic constant
of the folder being browsed.
- Permit Virtual Folders check box: When checked the Browse for folder
dialog box will display virtual sub folders and these may be chosen in the
dialog box. When the check box is cleared the Browse for Folder dialog will
not display virtual sub-folders, and they may not be chosen (the OK button
will be disabled when virtual folders are selected). NOTE: The OK button is
always enabled when the Use OnSelChange radio button is checked.
- Use OnSelChange radio button: When this button is checked the browse
dialog box component uses the OnSelChange event handler when the selected
folder changes. The event handler displays the name of the selected folder
in the dialog's status text and ensures the OK button is enabled.
- Use OnSelChangeEx radio button: When this button is checked the
browse dialog box component uses the OnSelChangeEx event handler when the
selected folder changes. The event handler displays there following information
in the dialog's status text: whether the selected folder is virtual or part
of the file system; the folder display name or path; and the index of the
folder's large icon in the system list. In addition, the large icon associated
with the folder is displayed in the main form.
Source Code
The main purpose of this demo is to examine the source code. The code of the
ShellFolderDemoForm unit illustrates the following:
- The DisplaySpecialFolders method (called from FormCreate)
uses the IPJSpecialFolderEnum interface, implemented by the TPJSpecialFolderEnum
class, to display details of all supported folders in the main window. The
code uses the TPJSpecialFolderInfo component to get the information
to display.
- The IsSelectionSupported method uses the TPJSpecialFolderInfo
component to test to see if the currently highlighted folder is supported
by the operating system.
- The BrowseButtonClick event handler sets up the TPJBrowseDialog
component to display the Browse for Folders dialog using the selected special
folder as its root node. The TPJBrowseDialog.Execute method is called
to display the dialog box. This causes the component's OnInitialise
event to fire - how this is handled is described below.
- The BrowseDialogInitialise method handles the TPJBrowseDialog.OnInitialise
event and adds an additional text control to the browse dialog. This text
control is used to display the symbolic constant of the special folder used
as root folder in the dialog.
- As folders are selected in the the browse dialog either the TPJBrowseDialog.OnSelChange
or TPJBrowseDialog.OnSelChangeEx events are handled by the BrowseDlgSelChange
or BrowseDlgSelChangeEx methods respectively, according to the state
of the Use OnSelChange and Use OnSelChangeEx radio buttons.
These event handlers perform as follows:
- BrowseDlgSelChange: This event handler simply displays the
selected folder's display name in the dialog's status text and ensures
the dialog's OK button is always enabled.
- BrowseDlgSelChangeEx: This event handler gets the display name
and path from the PIDL passed to the handler and displays folder information
according to whether the folder is virtual in the dialog's status text.
It then gets the handle of the icon associated with the folder and displays
it in the main form.
- When the browse dialog is closed, the TPJBrowseDialog.OnClose event
is triggered and handled by the BrowseDlgClose event handler. This
simply ensures that any icon displayed in the main window is cleared.
Please run the program and examine the source code to get an idea about how
to use the PJShellFolders unit.