I'm running into a very strange problem with the Vcl.FileCtrl function SelectDirectory (which is a thin wrapper around the ShBrowseForFolder Win32 API).
I'm using the following code to allow the user to browse for a file or a folder:
if SelectDirectory('Sélectionnez un élément à ajouter :', '', S, [sdNewFolder,
sdShowFiles, sdNewUI]) then
When executing this code, the "Browse for folder" dialog is correctly shown, displaying the content of the user's Desktop:
But when the number of items in the Desktop folder is excessively large (on my computer, I can reproduce the problem by having approx. 100 desktop icons), the same call produces a totally different display:
In this case, the Desktop items aren't shown anymore. I'm only allowed to explore my home folder and since I've lost the "My Computer" icon I cannot select a file/folder outside of this directory.
I'm searching what I'm missing here. Is there a limit in the number of subitems a root item can have for a correct display? Having a lot of desktop icons is certainely not a good practice, but as far as I know that shouldn't prevent this dialog to operate normally. I'm not sure if there is something wrong in the Delphi wrapper, or if that's a limitation of the API I didn't see on MSDN...
Any hint appreciated!
Yes, I can reproduce this behaviour. It's clearly a Windows limitation and the API in question does not offer you any way to increase buffers. I think your chances of working around it using SHBrowseForFolder
are close to zero. Because SHBrowseForFolder
is now a a legacy API.
If you are browsing for folders then you should use IFileOpenDialog
in folder selection mode. That's a a much nicer dialog that uses the new Vista dialogs. In Delphi that is wrapped by TFileOpenDialog
. Only use that if Win32MajorVersion>=6
though! For XP you need to call back on SHBrowseForFolder
.
if Win32MajorVersion>=6 then
begin
FileOpenDialog1.Title := 'Sélectionnez un élément à ajouter :';
FileOpenDialog1.Options := FileOpenDialog1.Options + [fdoPickFolders];
if FileOpenDialog1.Execute then
Beep;
end else
begin
// revert to SelectDirectory
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With