Mega Code Archive

 
Categories / Delphi / Functions
 

The GetFolder function

Title: The GetFolder function Question: How to use the windows shell api to call the windows dialog for choosing a folder. Answer: For some reason there is no metasymbol in the component toolbar of delphi to call the standard windows dialog for choosing a folder. Here is a function for this: uses ShlObj; ... function GetFolder(aRoot: integer; aCaption :string): string; var pPrograms,pBrowse: PItemIDList; hBrowseInfo: TBROWSEINFO; hPChar: PChar; begin if (not SUCCEEDED(SHGetSpecialFolderLocation(Getactivewindow, aRoot, pPrograms))) then EXIT; hPChar := StrAlloc(max_path); with hBrowseInfo do begin hwndOwner := Getactivewindow; pidlRoot := pPrograms; pszDisplayName := hPChar; lpszTitle := pChar(aCaption); ulFlags := BIF_RETURNONLYFSDIRS; lpfn := nil; lParam := 0; end; pBrowse := SHBrowseForFolder(hBrowseInfo); if (pBrowse nil) then if (SHGetPathFromIDList(pBrowse, hPChar)) then Result:= hPChar; StrDispose(hPChar); end;