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

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

问题描述

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



在此之前,我一直在使用SelectDirectory命令,但我认为我的程序的用户将难以查找指定的目录。 p>

我认为SelectDirectory是弱的,因为它可能是一个漫长的过程,搜索你想要的目录。例如,您要导航到应用程序数据目录。在那里导航多长或困难?最后,用户可能甚至不能达到他们想要的目录。



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





谢谢对于所有的答案。

解决方案

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

  with TFileOpenDialog.Create(nil)do 
try
选项:= [fdoPickFolders];
如果执行然后
ShowMessage(FileName);
终于
免费;
结束

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

 code>如果Win32MajorVersion> = 6然后
与TFileOpenDialog.Create(nil)做
尝试
标题:='选择目录';
选项:= [fdoPickFolders,fdoPathMustExist,fdoForceFileSystem]; // YMMV
OkButtonLabel:='Select';
DefaultFolder:= FDir;
FileName:= FDir;
如果执行然后
ShowMessage(FileName);
终于
免费;
end
else
如果SelectDirectory('Select Directory',ExtractFileDrive(FDir),FDir,
[sdNewUI,sdNewFolder])然后
ShowMessage(FDir)


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 Delphi, but preferably using what is provided by Delphi.

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.

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.

Thank you for all your answers.

解决方案

You can use the TFileOpenDialog (on Vista+):

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

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天全站免登陆