我想初始化一个这样的数组 -
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/