Delphi TFileOpenDialog、OpenDialog的區別,可使用TFileOpenDialog選擇資料夾
阿新 • • 發佈:2020-11-12
TOpenDialog和TFileOpenDialog使用效果差不多,但是TFileOpenDialog介面更好一點,同時可使用TFileOpenDialog選擇資料夾,但是TOpenDialog不能
TOpenDialog包裝了傳統的GetOpenFileName.它適用於所有版本的Windows.
TFileOpenDialog包裝了Vista中引入的基於COM的新對話方塊.因此,它僅適用於Vista及以上系統。
如果繼續使用TOpenDialog,則將在多選模式下獲得無限數量的檔案的好處.但是,如果您希望自定義對話方塊,並擁有新的對話方塊而不是難看的相容性對話方塊,則需要執行以下操作:
>在XP上,使用TOpenDialog和對話方塊模板方法.
>在Vista和更高版本上,使用TFileOpenDialog並通過IFileDialogCustomize實現自定義.
使用TFileOpenDialog選擇資料夾,TFileOpenDialog的 Options屬性選擇[fdoPickFolders];
var OpenDialog: TFileOpenDialog; SelectedFolder: string; begin OpenDialog := TFileOpenDialog.Create(MainForm); try OpenDialog.Options := OpenDialog.Options + [fdoPickFolders]; if not OpenDialog.Execute thenAbort; SelectedFolder := OpenDialog.FileName; finally OpenDialog.Free; end; end;