Lonewolf Online

The website of an amateur photographer, astronomer and petrolhead.

Browse For Folder Dialog

A class to create a browse for folder dialog box using Delphi and Windows API calls.

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;

 

Share/Save/Bookmark

 

What Others Are Saying

There are no comments for this item yet.

 

Have Your Say

 

 

 

 

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment. The authors reserve the right not to publish any comments that they believe are hateful, racist, demeaning or otherwise inappropriate.

    www.flickr.com
    This is a Flickr badge showing public photos and videos from Tim Trott. Make your own badge here.
  • Recent Additions
  • Search




  • Page copy protected against web site content infringement by Copyscape
This page was last updated on Monday, July 28th, 2008.
Unless otherwise stated, all photographs and content Copyright © 2000 - 2008 Tim Trott, All Rights Reserved. No graphics, photographs or content may be used without written permission.
Website Design and Graphics Copyright © 2005-2007 Tim Trott. home :: sitemap :: disclaimer:: contact