TFileOpenDialog in FireMonkey Application

百般思念 提交于 2019-12-01 06:44:46

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;
Denis Nazarenko
if SelectDirectory('Select a directory', chosenDirectory, chosenDirectory) then
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!