function SelectDirectory(handle:hwnd;const Caption: string; const Root: WideString;out Directory: string): Boolean;
var
  lpbi:_browseinfo;
  buf:array [0..MAX_PATH] of char;
  id:ishellfolder;
  eaten,att:cardinal;
  rt:pitemidlist;
  initdir:pwidechar;
begin
  result:=false;
  lpbi.hwndOwner:=handle;
  lpbi.lpfn:=nil;
  lpbi.lpszTitle:=pchar(caption);
  lpbi.ulFlags:=BIF_RETURNONLYFSDIRS+16;
  SHGetDesktopFolder(id);
  initdir:=pwchar(root);
  id.ParseDisplayName(0,nil,initdir,eaten,rt,att);
  lpbi.pidlRoot:=rt;
  getmem(lpbi.pszDisplayName,MAX_PATH);
  try
   result:=shgetpathfromidlist(shbrowseforfolder(lpbi),buf);
  except
   freemem(lpbi.pszDisplayName);
  end;
  if result then directory:=buf;
end;

解决方案 »

  1.   

    _browseinfo
    ishellfolder
    pitemidlist
    这几个类型找不到
      

  2.   

    不要那么麻烦。
    var
      sPath: string;
    begin
      if SelectDirectory('请选择目录', '', sPath) then
      begin
        if sPath[Length(sPath)] <> '\' then
          sPath := sPath + '\';
        ShowMessage(sPath);
      end;
    end;
      

  3.   

    游少爷你的selectdircetory函数体在哪里??
      

  4.   

    uses ShellAPI, ShlObj;procedure TForm1.Button1Click(Sender: TObject);
    var
      TitleName : string;
      lpItemID : PItemIDList;
      BrowseInfo : TBrowseInfo;
      DisplayName : array[0..MAX_PATH] of char;
      TempPath : array[0..MAX_PATH] of char;
    begin
      FillChar(BrowseInfo, sizeof(TBrowseInfo), #0);
      BrowseInfo.hwndOwner := Form1.Handle;
      BrowseInfo.pszDisplayName := @DisplayName;
      TitleName := 'Please specify a directory';
      BrowseInfo.lpszTitle := PChar(TitleName);
      BrowseInfo.ulFlags := BIF_RETURNONLYFSDIRS;
      lpItemID := SHBrowseForFolder(BrowseInfo);
      if lpItemId <> nil then begin
        SHGetPathFromIDList(lpItemID, TempPath);
        ShowMessage(TempPath);
        GlobalFreePtr(lpItemID);
      end;
    end;
    这样就行了,给分吧