Invoking the windows Browse For Folder dialog

Borland's SelectDirectory browser is quite ugly, here is how to invoke the Windows one instead.

uses

  ShlObj, ShellAPI;



......



function BrowseForFolder(handle : HWND; strTitle : string; var strPath : string) : boolean;

var info : TBROWSEINFO;

    path : array[0..MAX_PATH] of Char;

    items : PITEMIDLIST;

begin

 Result:=false;

 path:='';



 with info do

  begin

    hwndOwner:=handle;

    pidlRoot:=nil;

    pszDisplayName:=nil;

    lpszTitle:=PChar(strTitle);

    ulFlags:=BIF_RETURNONLYFSDIRS;

    lpfn:=nil;

  end;



 items:=SHBrowseForFolder(info);



 if assigned(items) then



  begin

    SHGetPathFromIDList(items,path);

    Result:=true;

  end;



 strPath:=Path;

end;

 

Share this article!

Follow us!

Find more helpful articles: