FireMonkey应用程序中的TFileOpenDialog [英] TFileOpenDialog in FireMonkey Application
问题描述
我正在使用FireMonkey,并希望用户使用由TFileOpenDialog提供的界面选择一个目录(我发现SelectDirectory界面最好过时 - 是的,即使使用sdNewUI选项)。
I'm using FireMonkey and want the user to select a directory using the interface supplied by a TFileOpenDialog (I find the SelectDirectory interface outdated at best - yes, even with the sdNewUI option).
首先,在FireMonkey应用程序中包含VCL.Dialogs单元(使用TFileOpenDialog)是不好的做法吗?
Firstly, Is it bad practice to include the VCL.Dialogs unit (to use a TFileOpenDialog) in a FireMonkey application?
其次,这只能在Windows Vista及以上版本中使用。这是检查兼容Windows版本的正确方法吗?
Secondly, this is still only possible with Windows Vista and above. Is this the correct way to check for a compatible Windows versions?
{IFDEF WIN32 or WIN64}
if Win32MajorVersion >= 6 then
// Create TOpenFileDialog with fdoPickFolders option
推荐答案
为了将来参考,使用IFileDialog创建Windows Vista及以上文件夹对话框:
For future reference, use of IFileDialog to create a Windows Vista and above folder dialog:
uses
ShlObj, ActiveX;
...
var
FolderDialog : IFileDialog;
hr: HRESULT;
IResult: IShellItem;
FileName: PChar;
Settings: DWORD;
begin
if Win32MajorVersion >= 6 then
begin
hr := CoCreateInstance(CLSID_FileOpenDialog,
nil,
CLSCTX_INPROC_SERVER,
IFileDialog,
FolderDialog);
if hr = S_OK then
begin
FolderDialog.GetOptions(Settings);
FolderDialog.SetOptions(Settings or FOS_PICKFOLDERS);
FolderDialog.GetOptions(Settings);
FolderDialog.SetOptions(Settings or FOS_FORCEFILESYSTEM);
FolderDialog.SetOkButtonLabel(PChar('Select'));
FolderDialog.SetTitle(PChar('Select a Directory'));
hr := FolderDialog.Show(Handle);
if hr = S_OK then
begin
hr := FolderDialog.GetResult(IResult);
if hr = S_OK then
begin
IResult.GetDisplayName(SIGDN_FILESYSPATH,FileName);
ConfigPathEdit.Text := FileName;
end;
end;
end;
end;
end;
这篇关于FireMonkey应用程序中的TFileOpenDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!