How can I set/get property value through RTTI for compex things like TStringGrid.Cells?

前端 未结 1 1945
别那么骄傲
别那么骄傲 2021-02-04 18:04

I have values stored in xml and lua code and accessing object\'s properties through RTTI.

var
  o, v: TValue; // o is current object
  a: TStringDynArray; // par         


        
1条回答
  •  星月不相逢
    2021-02-04 18:57

    Here's the simplest example I can think off to get and set the values from a string grid using RTTI:

    var
      ctx: TRttiContext;
      rttitype: TRttiType;
      rttiprop: TRttiIndexedProperty;
      value: TValue;
    ....
    rttitype := ctx.GetType(StringGrid1.ClassType);
    rttiprop := rttitype.GetIndexedProperty('Cells');
    value := rttiprop.GetValue(StringGrid1, [1, 1]);
    rttiprop.SetValue(StringGrid1, [1, 1], value.ToString + ' hello');
    

    I excised the error checking for the sake of simplicity. I'm going to assume that you already know how to check for errors.

    0 讨论(0)
提交回复
热议问题