简体   繁体   中英

Delphi SelectDirectory strange behaviour with network drive

I have had a bug report from a client. My program uses the Delphi select directory function to allow him to choose a few directories used by the program, which are allowed to be on a network drive. Here's the relevant extract from the bug report:

When trying to change the directory the network drives were not shown in the dialog. When opening "Computer" in the browse menu only local drives were shown. The roundabout solution is to leave the dialog open, disconnect the network drive, and re-connect the network drive. It then appears in the dialog. When changing the next folder location it must be done all over again. I found out that the main technician has been doing this frequently as it seems to reset.

At first I thought that this must be Windows not picking up the directories, so I asked him to check that the network location on both computers (the client and the one with the network drive) was set to Work, to check that the drive was mapped on the client, to check that network discovery was turned on, and to check that he could see the drives OK in Explorer. He did, but the bug persists.

I've not turned up anything on google or in QC reports concerning this, the documentation for SelectDirExtOpts seems to suggest that network drives should 'just work'.

So my question: has anyone encountered anything resembling this before? Is it likely to be a Windows issue, or is it Delphi?

Many thanks.

As long as you include that sdShowShares flag it should indeed just work.

If you look at the source of the SelectDirectory function you'll see that it isn't much more than setting things up for SHBrowseForFolder and reading the results.

SHBrowseForFolder is a Windows Shell API function:

function SHBrowseForFolder; external shell32 name 'SHBrowseForFolderW';

Delphi must interpreting the results it gets back from SHBrowseForFolder correctly, as the drives are shown correctly after reconnecting them. So I'd say it is a Windows problem on the client's machine.

Delphi SelectDirectory is a wrapper for the SHBrowseForFolder however - it should be noted that SelectDirectory function doesn't show mapped network drives for Delphi/C++ Builder versions on XE2 and older , as it seems. On newer versions, it appears to work properly and shows shared network drives.

The code which follows should work on all newer versions of Delphi:

AOptions := [sdNewUI, sdShowShares];
Result := SelectDirectory(Caption, Root, Directory, AOptions, nil);

Users of older Delphi/C++ Builder versions may want to call SHBrowseForFolderW directly. Some example code can be found at: https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shbrowseforfolderw

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM