you can compare the ShellItem TFileOpenDialog property ShellItem TFileOpenDialog property using StartsText and set the CanChange value according to the result.
check this sample.
uses StrUtils, ActiveX, ShlObj; {$R *.dfm} procedure TForm50.Button1Click(Sender: TObject); begin FileOpenDialog1.DefaultFolder:='C:\Program Files'; FileOpenDialog1.Execute; end; function GetItemName(Item: IShellItem; var ItemName: TFileName): HResult; var pszItemName: LPCWSTR; begin Result := Item.GetDisplayName(SIGDN_FILESYSPATH, pszItemName); if Failed(Result) then Result := Item.GetDisplayName(SIGDN_NORMALDISPLAY, pszItemName); if Succeeded(Result) then try ItemName := pszItemName; finally CoTaskMemFree(pszItemName); end; end; procedure TForm50.FileOpenDialog1FolderChanging(Sender: TObject;var CanChange: Boolean); var CurrentDir : TFileName; Result : HRESULT; begin Result := GetItemName(TFileOpenDialog(Sender).ShellItem,CurrentDir); CanChange := Succeeded(Result) and StartsText(TFileOpenDialog(Sender).DefaultFolder,CurrentDir); if not CanChange then ShowMessage('Sorry do you not have access to this folder'); end;
source share