How do you initialise a const array of TGUID from Interface type data, in Delphi?

后端 未结 7 747
谎友^
谎友^ 2020-12-18 00:43

I want to initialise an array like this -

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

But it results in -

[DCC Err         


        
7条回答
  •  离开以前
    2020-12-18 01:24

    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);
    

提交回复
热议问题