在 Delphi 中使用接口是否需要 GUID?
官方文档说它们是可选的。我知道 COM 互操作需要每个接口有一个唯一的标识符,但我看到的每个接口示例都有一个 GUID,无论它是否与 COM 一起使用?如果 GUID 不与 COM 一起使用,那么包含它有什么好处吗?
The official documentation says they are optional. I know COM interop requires a unique identifier for each interface but every interface example I see has a GUID whether it's used with COM or not? Is there any benefit to including a GUID if its not going to be used with COM?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我注意到一些方法,例如
Supports
(确定一个类是否符合特定接口)要求您先定义一个 GUID,然后才能使用它们。此页面通过以下信息确认了这一点:
以下是一些有关接口的有趣信息,其中指出:
在两个引号中都添加了强调。
阅读整篇文章也会让您意识到
QueryInterface
(需要 GUID)出于引用计数等原因在幕后使用。I've noticed that some methods such as
Supports
(to determine if a class conforms to a specific interface) require that you define a GUID before you can use them.This page confirms it with the following information:
Here's some interesting information about interfaces, which states:
Emphasis added in both quotes.
Reading this entire article also makes you realize that
QueryInterface
(which requires a GUID) is used behind the scenes for reasons such as reference counting.仅当您需要接口与 COM 兼容时。
不幸的是,这还包括使用
is
、as
运算符和QueryInterface
、Supports
函数 - 缺乏这些功能是相当困难的。限制。因此,虽然没有严格要求,但使用 GUID 可能更容易。否则,你只能得到相当简单的用法:Only if you need your interface to be compatible with COM.
Unfortunately, that also includes using
is
,as
operators andQueryInterface
,Supports
functions - the lack of which is rather limiting. So, while not strictly required, it's probably easier to use a GUID. Otherwise, you are left with rather simplistic usage only: