delphi - 在 Delphi 中使用接口(interface)是否需要 GUID?

标签 delphi interface guid

官方文档说它们是可选的。我知道 COM 互操作需要每个接口(interface)有一个唯一的标识符,但我看到的每个接口(interface)示例都有一个 GUID,无论它是否与 COM 一起使用?如果不与 COM 一起使用,包含 GUID 有什么好处吗?

最佳答案

我注意到一些方法,例如 Supports (确定一个类是否符合特定接口(interface))要求您先定义一个 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)出于引用计数等原因在幕后使用。

关于delphi - 在 Delphi 中使用接口(interface)是否需要 GUID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2992183/

相关文章:

mysql - Delphi 2009、MyDAC 和关系数据库

java - 为什么引入 Autocloseable 而不是扩展 Closeable 中可能出现的异常

java - 如何使用实例变量隐藏接口(interface)变量

Java:我可以要求一个子类来定义一个属性值吗?

mysql - 在 MySQL 中为现有数据生成 GUID?

c# - 如何为每个已安装的实例生成新的 guid?

delphi - 数据网格导出为 pdf

delphi - 将多个 TObject 流式传输到 TMemoryStream

mysql - 字符串中的双连字符可以转义吗?

java - 错误 : Bound mismatch, Collections.sort、接口(interface)、compareTo 方法