Knowledge Base

ShellBrowser Delphi Components



Question / Problem

How can I forbid entering a specific folder in a JamShellTree and JamShellList?

Answer / Solution

You can use the TJamShellTree.OnChanging event like this:
uses ShellBrowser;
const
    forbiddenPath: String = 'C:\Windows';
procedure TMainForm.ShellTreeChanging(Sender: TObject; Node: TTreeNode; var AllowChange: Boolean);
var
    shellNode: TJamShellTreeNode;
begin
    shellNode := node as TJamShellTreeNode;
    if (ShellBrowser.SamePath(shellNode.FullPath, forbiddenPath)) then
        AllowChange := false;
end; 

To achieve the same result in the JamShellList, use the TJamShellList.PathChanged event:
uses ShellBrowser;

private
    lastPath: String;
const
    forbiddenPath: String = 'C:\Windows';

procedure TMainForm.ShellListPathChanged(Sender: TObject);
begin
    if (ShellBrowser.SamePath(ShellList.Path, forbiddenPath)) then
        ShellList.Path := lastPath
    else
        lastPath := ShellList.Path;
end;

You can also use the OnBeforeShellCommand event and use the AllowExecute parameter to prevent the execution. The Command parameter when opening a folder might be "default" or "open".