Delphi 2010新機能之:Rttiユニット(4):TRttiRecordType
1257 ワード
次に、TPointを例に、TRttiRecordTypeで構成の情報を読み出す.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses Rtti;
procedure TForm1.Button1Click(Sender: TObject);
var
t: TRttiRecordType;
f: TRttiField;
begin
Memo1.Clear;
t := TRttiContext.Create.GetType(TypeInfo(TPoint)).AsRecord;
Memo1.Lines.Add(t.QualifiedName);
Memo1.Lines.Add(Format('Size: %d', [t.TypeSize]));
Memo1.Lines.Add(EmptyStr);
Memo1.Lines.Add(Format(' : %d', [Length(t.GetFields)]));
Memo1.Lines.Add(Format(' : %d', [Length(t.GetMethods)]));
Memo1.Lines.Add(Format(' : %d', [Length(t.GetProperties)]));
Memo1.Lines.Add(EmptyStr);
Memo1.Lines.Add(' :');
for f in t.GetFields do Memo1.Lines.Add(f.ToString);
end;
end.