加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

在Delphi中是否需要使用GUID?

发布时间:2020-12-15 10:04:12 所属栏目:大数据 来源:网络整理
导读:官方文件说它们是可选的.我知道COM interop需要每个接口的唯一标识符,但是我看到的每个接口示例都有一个GUID是否与COM一起使用?如果包含GUID不会与COM一起使用,是否有任何好处? 解决方法 我注意到一些方法,如 Supports (要确定一个类是否符合特定接口)需要
官方文件说它们是可选的.我知道COM interop需要每个接口的唯一标识符,但是我看到的每个接口示例都有一个GUID是否与COM一起使用?如果包含GUID不会与COM一起使用,是否有任何好处?

解决方法

我注意到一些方法,如 Supports(要确定一个类是否符合特定接口)需要您定义一个GUID才能使用它们.

This page确认了以下信息:

Note: The SysUtils unit provides an
overloaded function called Supports
that returns true or false when class
types and instances support a
particular interface represented by a
GUID.
The Supports function is used in
the manner of the Delphi is and as
operators. The significant difference
is that the Supports function can take
as the right operand either a GUID or
an interface type associated with a
GUID
,whereas is and as take the name
of a type. For more information about
is and as,see Class References.

这里有一些interesting information about interfaces,其中指出:

Why does an interface need to be
uniquely identifiable? The answer is
simple: because Delphi classes can
implement multiple interfaces. When an
application is running,there has to
be a mechanism that will get pointer
to an appropriate interface from an
implementation. The only way to find
out if an object implements an
interface and to get a pointer to
implementation of that interface is
through GUIDs
.

重点加在两个引号.

阅读整篇文章也让您意识到QueryInterface(需要GUID)在后台使用,原因如引用计数.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读