A class to create a browse for folder dialog box.
Create a unit with the following code.
Usage:
var Browse: TBrowseForFolderDialog;
begin
Browse := TBrowseForFolderDialog.Create;
Browse.Title := 'Please Specify HTML Output Dir';
Browse.Execute;
myFolderPath := Browse.Path;
Browse.Free;
end;
Class Code
type
TBrowseForFolderDialog = class
private
bi: TBROWSEINFO;
str: array[0..MAX_PATH] of char;
pIDListItem: PItemIDList;
pStr: PChar;
procedure SetTitle(Title: string);
function GetTitle: string;
function GetPath: string;
public
property Title: string read GetTitle write SetTitle;
function Execute: Boolean;
property Path: string read GetPath;
end;
procedure TBrowseForFolderDialog.SetTitle(Title: string);
begin
bi.lpszTitle := PChar(Title);
end;
function TBrowseForFolderDialog.GetTitle: string;
begin
Result := bi.lpszTitle;
end;
function TBrowseForFolderDialog.GetPath: string;
begin
Result := pStr;
end;
function TBrowseForFolderDialog.Execute: Boolean;
begin
bi.hwndOwner := GetActiveWindow;
bi.pidlRoot := nil;
bi.pszDisplayName := @str;
bi.ulFlags := bif_RETURNONLYFSDIRS;
bi.lpfn := nil;
pIDListItem := SHBrowseForFolder(bi);
if pIDListItem <> nil then
begin
pStr := @Str;
SHGetPathFromIDList(pIDListItem, pStr);
Result := True;
end
else
Result := False;
end;



