下面代码中prop.GetAttributes是获得什么属性?他和tp.GetProperties 有什么区别吗?class function TmyXmlFieldAttribute.GetValueByName(AObject: TObject;
APropName: string): TValue;
var
ctx: TRttiContext;
tp: TRttiType;
prop: TRttiProperty;
att: TCustomAttribute;
begin
tp := ctx.GetType(AObject.ClassType);
// 查找所有属性
for prop in tp.GetProperties do
begin
// 查找属性特性
for att in prop.GetAttributes do
begin
if att.InheritsFrom(TmyXmlFieldAttribute) then
begin
if CompareText(TmyXmlFieldAttribute(att).fName,APropName)=0 then
begin
Exit(prop.GetValue(AObject));
end;
end;
end;
end;
Result := nil;
end;DelphiRtti函数
APropName: string): TValue;
var
ctx: TRttiContext;
tp: TRttiType;
prop: TRttiProperty;
att: TCustomAttribute;
begin
tp := ctx.GetType(AObject.ClassType);
// 查找所有属性
for prop in tp.GetProperties do
begin
// 查找属性特性
for att in prop.GetAttributes do
begin
if att.InheritsFrom(TmyXmlFieldAttribute) then
begin
if CompareText(TmyXmlFieldAttribute(att).fName,APropName)=0 then
begin
Exit(prop.GetValue(AObject));
end;
end;
end;
end;
Result := nil;
end;DelphiRtti函数
TTest = class
[XXXXX]
FTest:Integer;
end;方括号里面就是你说的Attributes信息
能不能帮我解释一下
ctx: TRttiContext;
tp: TRttiType;
prop: TRttiProperty;
att: TCustomAttribute;这些类的详细用法呢?谢谢了!