Author: Jonas Bilinkevicius
I'm looking for code that will let me implement a Win32 look and feel "Browse for
Folder" directory picker. Like the one used in Project Options - > Directories/
Conditionals interface.
Answer:
1 2 procedure TMainForm.BrowseFolderActionExecute(Sender: TObject);
3 var4 pidl, pidlSelected: PItemIDList;
5 bi: TBrowseInfo;
6 szDirName: array[0..260] of AnsiChar;
7 begin8 {Get the root PIDL of the network neighborhood tree}9 if SHGetSpecialFolderLocation(Handle, CSIDL_DESKTOP, pidl) = NOERROR then10 begin11 {Populate a BROWSEINFO structure}12 bi.hwndOwner := Handle;
13 bi.pidlRoot := pidl;
14 bi.pszDisplayName := szDirName;
15 bi.lpszTitle := 'Select directory';
16 bi.ulFlags := BIF_RETURNONLYFSDIRS;
17 bi.lpfn := nil;
18 bi.lParam := 0;
19 bi.iImage := -1;
20 {Display the "Browse For Folder" dialog box}21 pidlSelected := SHBrowseForFolder(bi);
22 {NULL indicates that Cancel was selected from the dialog box}23 if pidlSelected < > nilthen24 begin25 SHGetPathFromIDList(pidlSelected, szDirName);
26 ShowMessage(szDirName);
27 {Release the PIDL of the computer name}28 CoTaskMemFree(pidlSelected);
29 end;
30 {Release the PIDL of the network neighborhood tree}31 CoTaskMemFree(pidl);
32 end;
33 end;