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 then Abort; SelectedFolder := OpenDialog.FileName; finally OpenDialog.Free; end; end;