我正在使用FireMonkey并希望用户使用TFileOpenDialog提供的接口选择目录(我发现SelectDirectory接口最好过时 – 是的,即使使用sdNewUI选项). 首先,在FireMonkey应用程序中包含VCL.Dialogs单元(使用TFil
首先,在FireMonkey应用程序中包含VCL.Dialogs单元(使用TFileOpenDialog)是不好的做法吗?
其次,这仍然只适用于Windows Vista及更高版本.这是检查兼容Windows版本的正确方法吗?
{IFDEF WIN32 or WIN64} if Win32MajorVersion >= 6 then // Create TOpenFileDialog with fdoPickFolders option为了将来参考,使用IFileDialog创建Windows Vista及以上文件夹对话框:
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;