English (en) │
français (fr) │
* * * A FINIR * * *
TShellListView displays files according to its Root property. The Root property contains the whole path from the drive letter to the current directory. If using it to show the complete path including a selected file, then you need to append a slash ('\' or '/' in UNIX) to Root, as in:
pathname := '"' + svList.Root + '\' + svList.Selected.Caption + '"';
svList is the name of a TShellListView object, and
svList.Selected.Caption contains the name of a file selected by the user.
pathname is a string variable containing the entire path from the drive letter to the file name and extension. The double quotes are recommended to be applied in MS-Windows if the path contains spaces. This makes the usual process of escaping spaces in filenames with
%20 unnecessary in Windows.
Talking to TShellTreeView
There is little coding to do in getting TShellListView to communicate with TShellTreeView. In the Object Inspector, under the Events tab, for TShellTreeView, set the event "ShellListView" to the name of your TShellListView object. This ought to be already stored on a dropdown menu if both TShellListView and TShellTreeView objects are deployed on your form. For completeness, so that both objects respond to each other, set the ShellTreeView event of TShellListView to the name of your TShellTreeView object.
Alternatively, if we let svList be the TShellListView object; and svTree be the TShellTreeView object, then these properties can be set programmatically:
svList.ShellTreeView := svTree; svTree.ShellListView := svList;
The result is to invoke Explorer-like behavior in their responsiveness.
In Windows, the generic command for opening a file in TShellListView is
pathname is the path to the file. For this you should remember to add
lclintf to your
uses clause. Other operating systems can get away with using
OpenURL(pathname), except that spaces must be escaped with a
%20 string, and
file:// must prepend the pathname. Example:
Contrast this with the Windows convention:
OpenURL is not recommended for use in Windows for opening documents using the file:// URI scheme.
OpenDocument also acts as a Boolean function, it returns false if there is no way in the registry to open the file. If we let
pathname be the full path to the file from the drive letter to the filename, this statement will open the document if
if not OpenDocument(pathname) then // no method to display this file type ShowMessage('Cannot display ' + pathname);
Faire face à l'étrangeté
When running a program with this object, you may notice that double-clicking on a filename will allow you to edit it or delete its name entirely by default. These sorts of changes appear to have no effect on the file itself. To stop this behavior, set the ReadOnly property to True.