在Delphi中,如何从接口类型数据初始化一个TGUID的const数组? [英] How do you initialise a const array of TGUID from Interface type data, in Delphi?

查看:432
本文介绍了在Delphi中,如何从接口类型数据初始化一个TGUID的const数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to initialise an array like this -

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

但它会导致 -

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

所以看看会发生什么我试过这个 -

So to see what would happen I tried this -

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

哪些导致了这个!

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

多么奇怪!当然IInterface是一个或另一个,但它似乎固执地转换成错误的类型。

How strange! Surely IInterface is one or the other, but it seems to stubbornly transform into the wrong type.

推荐答案

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

You can pull the GUIDs from the interface declarations and declare them as (string) constants. You can then use these constants in your interface declarations and your array constant declarations. The compiler accepts valid GUID strings where TGUID is expected. Invalid strings result in E2204 "Improper GUID syntax" compile error.

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中,如何从接口类型数据初始化一个TGUID的const数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆