Delphi XE----Rtti单元一(TRttiContext)
2021-03-07 16:30
标签:send proc RoCE format rtt length name png get 通过 Rtti 单元的 TRttiContext(是个 record), 可以方便地获取类的方法、属性、字段的列表. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Delphi XE----Rtti单元一(TRttiContext) 标签:send proc RoCE format rtt length name png get 原文地址:https://www.cnblogs.com/redhat588/p/12821742.htmluses
System.Rtti;
//TRttiContext.GetTypes
procedure TForm1.Button1Click(Sender: TObject);
var
ctx: TRttiContext;
t: TRttiType;
begin
Memo1.Clear;
for t in ctx.GetTypes do
Memo1.Lines.Add(t.Name);
end;
//获取 TButton 类的方法
procedure TForm1.Button2Click(Sender: TObject);
var
ctx: TRttiContext;
t: TRttiType;
m: TRttiMethod;
begin
Memo1.Clear;
t := ctx.GetType(TButton);
//for m in t.GetMethods do Memo1.Lines.Add(m.Name);
for m in t.GetMethods do
Memo1.Lines.Add(m.ToString);
end;
//获取 TButton 类的属性
procedure TForm1.Button3Click(Sender: TObject);
var
ctx: TRttiContext;
t: TRttiType;
p: TRttiProperty;
begin
Memo1.Clear;
t := ctx.GetType(TButton);
//for p in t.GetProperties do Memo1.Lines.Add(p.Name);
for p in t.GetProperties do
Memo1.Lines.Add(p.ToString);
end;
//获取 TButton 类的字段
procedure TForm1.Button4Click(Sender: TObject);
var
ctx: TRttiContext;
t: TRttiType;
f: TRttiField;
begin
Memo1.Clear;
t := ctx.GetType(TButton);
//for f in t.GetFields do Memo1.Lines.Add(f.Name);
for f in t.GetFields do
Memo1.Lines.Add(f.ToString);
end;
procedure TForm1.Button5Click(Sender: TObject);
var
ctx: TRttiContext;
t: TRttiType;
ms: TArray
文章标题:Delphi XE----Rtti单元一(TRttiContext)
文章链接:http://soscw.com/index.php/essay/61422.html