delphi - 在 Delphi 中,如何从接口(interface)类型数据初始化 TGUID 常量数组?

标签 delphi interface guid array-initialize

我想初始化一个这样的数组 -

Const MyArray : Array[0..0] Of TGUID = (IInterface);

但结果是 -

[DCC Error] Test.pas(10): E2010 Incompatible types: 'TGUID' and 'string'

所以为了看看会发生什么,我尝试了这个 -

Const MyArray : Array[0..0] Of String = (IInterface);

结果就是这样!

[DCC Error] Test.pas(10): E2010 Incompatible types: 'string' and 'TGUID'

多么奇怪啊!当然,IInterface 是其中之一,但它似乎顽固地转变成错误的类型。

最佳答案

您可以从接口(interface)声明中提取 GUID 并将它们声明为(字符串)常量。然后,您可以在接口(interface)声明和数组常量声明中使用这些常量。编译器接受有效的 GUID 字符串,其中需要 TGUID。无效的字符串会导致 E2204“不正确的 GUID 语法”编译错误。

const
  MyGuid1 = '{99BDAB12-B1B6-41B0-9BF1-2C1DB3D8EC70}';
  MyGuid2 = '{8C7CD303-8D81-469B-99ED-E1F163E9036F}';

type
  IMyInterface1 = interface
    [MyGuid1]
  end;

  IMyInterface2 = interface
    [MyGuid2]
  end;

const
  MyArray: array[0..1] of TGUID = (MyGuid1, MyGuid2);

关于delphi - 在 Delphi 中,如何从接口(interface)类型数据初始化 TGUID 常量数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/704346/

相关文章:

delphi - 发送 ASCII 而不是字符串

delphi - 我应该在哪里存储IDE组件编辑器用户首选项?

delphi - TClientDataset - 是否可以按 unicode 列名称进行过滤?

interface - F# 中的对象表达式和捕获的状态

java - 私有(private)接口(interface)方法,示例用例?

c# - 比较不同创建的 GUID 时是否有更大的机会发生冲突?

guid - 如何合并两个GUID值

delphi - 为此我需要什么单位范围?

typescript - 实现编译器不跟随的链

sql-server - SQL Server : ~2000 Heap Tables all using GUID Uniqueidentifier - Possible Clustered Indexing?