gpt4 book ai didi

delphi - 使用 TOpenDialog 选择目录

转载 作者:行者123 更新时间:2023-12-03 14:32:37 28 4
gpt4 key购买 nike

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

在此之前,我一直在使用 SelectDirectory 命令,但我认为对于我的程序的用户来说,查找指定的目录会很困难。

我认为 SelectDirectory 很“弱”,因为搜索所需目录时它可能是一个漫长的过程。例如,您想要导航到应用程序数据目录。导航到那里需要多长时间或有多困难?最终,用户甚至可能无法到达他们想要的目录。

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

enter image description here

感谢您的所有回答。

最佳答案

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

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

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

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)

关于delphi - 使用 TOpenDialog 选择目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7422689/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com