TFileOpenDialog in FireMonkey Application

江枫思渺然 提交于 2019-12-01 04:54:31

问题


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).

Firstly, Is it bad practice to include the VCL.Dialogs unit (to use a TFileOpenDialog) in a FireMonkey application?

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

回答1:


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;



回答2:


if SelectDirectory('Select a directory', chosenDirectory, chosenDirectory) then


来源:https://stackoverflow.com/questions/10998309/tfileopendialog-in-firemonkey-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!