使用 TOpenDialog 选择目录 [英] Selecting a directory with TOpenDialog

查看:32
本文介绍了使用 TOpenDialog 选择目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很想知道我可以通过 TOpenDialog 选择目录的各种方式,无论是下载新组件还是使用 Delphi 提供的内容,但最好使用 Delphi 提供的内容.

I'd really like to know the various ways I could select a directory with the TOpenDialog, whether it be downloading a new component or using what is provided by Delp but preferably using what is provided by Delphi.

在此之前,我一直在使用 SelectDirectory 命令,但我认为我的程序的用户很难找到指定的目录.

Prior to this, I have been using the SelectDirectory command but I think it'd be a difficulty for the users of my program to look for the specified directory.

我认为 SelectDirectory 是弱的",因为在搜索您想要的目录时它可能是一个漫长的过程.例如,您想导航到 Application Data 目录.在那里导航需要多长时间或多长时间?最后,用户甚至可能无法到达他们想要的目录.

I think the SelectDirectory is 'weak' because it can be a long process when searching for the directory you want. Say for example, you want to navigate to the Application Data directory. How long or difficult would it be to navigate there? In the end, users may not even reach their desired directory.

我需要这样的东西,用户可以将目录复制并粘贴到顶部的目录地址栏中.

I need something like this where the user can copy and paste directories into the directory address bar at the top there.

感谢您的所有回答.

推荐答案

您可以使用 TFileOpenDialog(在 Vista+ 上):

You can use the TFileOpenDialog (on Vista+):

with TFileOpenDialog.Create(nil) do
  try
    Options := [fdoPickFolders];
    if Execute then
      ShowMessage(FileName);
  finally
    Free;
  end;

就我个人而言,我总是在 Vista+ 上使用 TFileOpenDialog 并在 XP 上使用 SelectDirectory(好的!)回退,如下所示:

Personally, I always use the TFileOpenDialog on Vista+ and fallback using the SelectDirectory (the good one!) on XP, like this:

if Win32MajorVersion >= 6 then
  with TFileOpenDialog.Create(nil) do
    try
      Title := 'Select Directory';
      Options := [fdoPickFolders, fdoPathMustExist, fdoForceFileSystem]; // YMMV
      OkButtonLabel := 'Select';
      DefaultFolder := FDir;
      FileName := FDir;
      if Execute then
        ShowMessage(FileName);
    finally
      Free;
    end
else
  if SelectDirectory('Select Directory', ExtractFileDrive(FDir), FDir,
             [sdNewUI, sdNewFolder]) then
    ShowMessage(FDir)

这篇关于使用 TOpenDialog 选择目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆