How to access record properties?

I need to access, write properties, and set / get the values ​​of this property. Firstly, I want to access the properties. But I can not.

What's wrong? Ver: Delphi XE6.

code example:

type
  TmyRecord = record
  private
    Str : String;
  public
    property StrProp :String read Str;  
  end;


procedure TForm1.Button3Click(Sender: TObject);
var
 c : TRttiContext;
 t : TRttiType;
 field : TRttiField;
 prop : TRttiProperty;
begin
 c := TRttiContext.Create;
 try
   Memo1.Lines.Append('Fields');
   for field in c.GetType(TypeInfo(TMyRecord)).GetFields do
   begin
     t := field.FieldType;
     Memo1.Lines.Append('Field:'+field.Name);
     Memo1.Lines.Append('RttiType:'+t.ClassName);
   end;

   Memo1.Lines.Append('Properties');
   for prop in c.GetType(TypeInfo(TMyRecord)).GetProperties do
   begin
     t := prop.PropertyType;
     Memo1.Lines.Append('Property:'+prop.Name);
     Memo1.Lines.Append('RttiType:'+t.ClassName);
   end;

 finally
   c.Free
 end;

end;
+1
source share
1 answer

Your problem is that RTLC is not available for recording properties, as already reported in 2009, but still not fixed ( QC # 78110 ).

Edit: And not yet fixed in 2017 ( RSP-19303 ).

+5
source

Source: https://habr.com/ru/post/1570188/


All Articles