新的 TFileOpenDialog 和旧的 TOpenDialog 有什么区别?
新的 TFileOpenDialog 和旧的 TOpenDialog 有什么区别?
在我的计算机(Win 7/DXE)中,当我运行代码时,对话框看起来是一样的。
What is the difference between the new TFileOpenDialog and the old TOpenDialog?
In my computer (Win 7/DXE), when I run the code, the dialogs look the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当满足以下条件时,
TOpenDialog
执行TFileOpenDialog
:UseLatestCommonDialogs
为 true(这是默认值)OnIncludeItem
、OnClose
或OnShow
事件因此,当您仍在系统上使用
TOpenDialog
时,您可能最终会遇到这样的情况自动执行在大多数情况下,TFileOpenDialog
,这解释了为什么它们对您来说看起来相同。备注:
TFileOpenDialog
不会退回到旧版 Windows 系统(XP 及以下) - 它只是引发异常。相反,TOpenDialog
会进行某种“向前跌倒”。TOpenDialog
executesTFileOpenDialog
when the following conditions are met:UseLatestCommonDialogs
is true (which is the default)OnIncludeItem
,OnClose
orOnShow
events are setSo while still using
TOpenDialog
on your system you may likely end up automagically executingTFileOpenDialog
in most cases, which explains why they are looking the same for you.Remark:
TFileOpenDialog
does not fall back on older Windows systems (XP and under) - it just raises an exception. On the opposite,TOpenDialog
does some sort of "fall forward".TOpenDialog
包装了传统的GetOpenFileName
。它适用于所有版本的 Windows。TFileOpenDialog
包装了 Vista 中引入的新的基于 COM 的对话框。因此它仅适用于 Vista 或更高版本。它比旧的对话框具有更多的功能,最显着的是与搜索的紧密集成。Vista通用对话框

兼容性通用对话框

如果调用,
GetOpenFileName
API 实际上会在大多数情况下生成新对话框正确,所以你实际上无法区分。也就是说,历史上 VCL 的 GetOpenFileName 包装器的实现并不精确,并且总是导致显示兼容性对话框。那么新的 COM 对话框必须提供什么功能呢?
新对话框提供了更简单的自定义界面,但失去了一些通用性。如果您在 Vista 或更高版本上使用基于旧对话框模板的自定义与
GetOpenFileName
,则对话框会降级为缺乏功能的丑陋兼容性版本。新对话框的另一大优点是能够选择无限数量的文件。旧的 GetOpenFileName 接口在固定大小的缓冲区中返回多选文件名。这可能是一个真正的限制,在我自己的代码中,当我的应用程序在 XP 上运行时,我不得不修改 VCL 代码以使该缓冲区更大。
如果可能,
TOpenDialog
会将工作委托给TFileOpenDialog
。它使用的测试要求满足以下所有条件:Dialogs.UseLatestCommonDialogs
全局布尔变量为 true(默认为 true)。这允许您禁用新 COM 对话框的使用(如果您选择这样做)。OnIncludeItem
、OnClose
和OnShow
事件均未分配。据推测,这些不能由TFileOpenDialog
触发。总结
如果您继续使用
TOpenDialog
,那么您将获得多选模式下无限数量的文件的好处。但是,如果您希望自定义对话框,并拥有新的对话框而不是丑陋的兼容性对话框,那么您需要执行以下操作:TOpenDialog
和对话框模板方法。TFileOpenDialog
并使用IFileDialogCustomize
实现自定义。TOpenDialog
wraps the traditionalGetOpenFileName
. It works on all versions of Windows.TFileOpenDialog
wraps the new COM based dialog that was introduced in Vista. It therefore only works on Vista or later. It has more functionality than the older dialogs, most notably the tight integration with search.Vista common dialog

Compatibility common dialog

The
GetOpenFileName
API will in fact produce the new dialogs in most situations, if called correctly, so you can't actually tell the difference. That said, historically the VCL's wrapper forGetOpenFileName
was implemented imprecisely and always resulted in the compatibility dialog being shown.But what does the new COM dialog have to offer then?
The new dialog offers a much easier customisation interface at the loss of some generality. If you use the old dialog template based customisation with
GetOpenFileName
on Vista or later then the dialogs degrade to ugly compatibility versions that lack functionality.The other big advantage of the new dialogs is the ability to select unlimited number of files. The old
GetOpenFileName
interface returned multi-select filenames in a fixed size buffer. This can be a real limitation and in my own code I have had to hack the VCL code to make this buffer larger for when my app runs on XP.TOpenDialog
will delegate the work toTFileOpenDialog
if possible. The test it uses requires all of the following to be true:Dialogs.UseLatestCommonDialogs
global boolean variable is true (default is true). This allows you to disable the use of the new COM dialog should you elect to do so.OnIncludeItem
,OnClose
andOnShow
events are all not assigned. Presumably these cannot be fired byTFileOpenDialog
.Summary
If you continue to use
TOpenDialog
then you will reap the benefit of unlimited number of file in multi-select mode. However, if you wish to customise the dialog, and have the new dialogs rather than the ugly compatibilty dialogs, then you need to do the following:TOpenDialog
and the dialog template method.TFileOpenDialog
and implement customisation withIFileDialogCustomize
.