如何枚举接口中的所有字符串属性?

时间:2022-10-30 09:37:06

I want (if possible) to enumerate all string properties in an interface that looks like this:

我想(如果可能的话)枚举接口中的所有字符串属性,如下所示:

IXMLDocumentSummaryType = interface(IXMLNode)
    ['{AD394EAD-1253-4CA5-9F0A-76122CB53D88}']
    { Property Accessors }
    function Get_Uid: UnicodeString;
    function Get_RsUid: UnicodeString;
    //etc

    { Methods & Properties }
    property Uid    : UnicodeString read Get_Uid write Set_Uid;
    property RsUid  : UnicodeString read Get_RsUid write Set_RsUid;
    property Meta   : UnicodeString read Get_Meta write Set_Meta;
    property Error  : UnicodeString read Get_Error write Set_Error;
  end;

There are lots of text properties and I am interested in only 43. So, I have the name of those 43 in a static array.

有很多文本属性,我只对43感兴趣。所以,我在静态数组中有43个名字。

   Fields: array[0..42] of RSummary= (
        (Name: 'RsUid' ; Value: ''),
        (Name: 'GbUid' ; Value: ''),
        etc...
    );

Now I would like to enumerate the properties and automatically put the values of those properties in the array. I have Delphi XE7.

现在我想枚举属性并自动将这些属性的值放在数组中。我有Delphi XE7。

I have tried this:

我试过这个:

var
  C: TRttiContext;
  T: TRttiType;
  F: TRttiField;
  P: TRttiProperty;
begin
  T:= C.GetType(IXMLDocumentSummaryType)   <----- not working

1 个解决方案

#1


Interfaces properties are very different from class properties. An interface only has methods and the properties are just sugar.

接口属性与类属性非常不同。接口只有方法,属性只是糖。

You won't get RTTI for interface properties because there is no such RTTI.

您不会获得接口属性的RTTI,因为没有这样的RTTI。

#1


Interfaces properties are very different from class properties. An interface only has methods and the properties are just sugar.

接口属性与类属性非常不同。接口只有方法,属性只是糖。

You won't get RTTI for interface properties because there is no such RTTI.

您不会获得接口属性的RTTI,因为没有这样的RTTI。