uses
  ShlObj;function SelectFolderDialog(const Handle: integer;
  const Caption: string;
  const InitFolder: WideString;
  var SelectedFolder: string): boolean;
var
  BInfo: _browseinfo;
  Buffer: array[0..MAX_PATH] of
  Char;
  ID: IShellFolder;
  Eaten, Attribute: Cardinal;
  ItemID:
  PItemidlist;
begin
  Result := False;
  BInfo.HwndOwner := Handle;
  BInfo.lpfn := nil;
  BInfo.lpszTitle := Pchar(Caption);
  BInfo.ulFlags := BIF_RETURNONLYFSDIRS + BIF_NEWDIALOGSTYLE;
  SHGetDesktopFolder(ID);
  ID.ParseDisplayName(0, nil,
  PWideChar(InitFolder), Eaten, ItemID, Attribute);
  BInfo.pidlRoot := ItemID;
  GetMem(BInfo.pszDisplayName, MAX_PATH);
  try
    if SHGetPathFromIDList(SHBrowseForFolder(BInfo), Buffer) then
    begin
      SelectedFolder := Buffer;
      if Length(SelectedFolder) <> 3 then SelectedFolder := SelectedFolder + '\';
      result := True;
    end
    else
    begin
      SelectedFolder := '';
      Result := False;
    end;
  finally
    FreeMem(BInfo.pszDisplayName);
  end;
end;
  var
  NewDir: string;
调用
  if SelectFolderDialog(handle, '选择文件夹', '', NewDir) then
    xxxx使用如上的方法显示选择文件夹框
但是无法让它显示上次打开的路径。
请大家给予一些帮助,谢谢

解决方案 »

  1.   

    这样不就得了
    var
      NewDir: string = #13#10; // 改定义为全局变量procedure TForm1.btn1Click(Sender: TObject);
    begin
      // NewDir 保存着上传选择的路径
      if SelectFolderDialog(handle, '上次路径:' + #13#10 + NewDir, '', NewDir) then;
    end;另外_browseinfo记录有个lpfn回调函数成员,可以利用  
      

  2.   


    var
      NewDir: string = ''; // 改定义为全局变量procedure TForm1.btn1Click(Sender: TObject);
    begin
      // NewDir 保存着上次选择的路径
      if SelectFolderDialog(handle, '上次路径:' + #13#10 + NewDir, '', NewDir) then;
    end;csdn抽了,发了N次回贴都提示回帖失败请重试
      

  3.   

    TOpenDialog打开就是上一次的路径啊,为啥不用?
      

  4.   

    TOpenDialog打开就是上一次的路径啊,为啥不用?opendialog可以选择文件夹? 我试了它的所有选项 也不行啊
      

  5.   

    TOpenDialog打开就是上一次的路径啊,为啥不用?opendialog可以选择文件夹? 我试了它的所有选项 也不行啊
    哦 那个opendialog有一个ofoldstyledialog 的选项 可以选择文件夹