RTTiでいくつか問題が発生しました..レコードタイプのすべての定数値を列挙したいです
type TMyRecord = record
const
value1: Integer=10;
value2: Integer=13;
value3: Integer=18;
value4: Integer=22;
end;
procedure TForm3.Button1Click(Sender: TObject);
var
ctx:TRttiContext ;
Field:rtti.TRttiField ;
begin
for Field in ctx.GetType(TypeInfo(TMyRecord)).GetFields do
ListBox1.Items.Add(Field.Name ); // i got nothing
end;
しかし、私のレコードが定数でない場合、私のコードは正常に機能します
type TMyRecord = record
value1: Integer;
value2: Integer;
value3: Integer;
value4: Integer;
end;
procedure TForm3.Button1Click(Sender: TObject);
var
ctx:TRttiContext ;
Field:rtti.TRttiField ;
begin
for Field in ctx.GetType(TypeInfo(TMyRecord)).GetFields do
ListBox1.Items.Add(Field.Name ); //its work
end;