读书人

怎么判断某个对象是否有某个属性(publ

发布时间: 2012-02-28 13:06:34 作者: rapoo

如何判断某个对象是否有某个属性(public级别的属性)
GetPropInfo可以得到某个对象的Published出来的属性,但是无法判断Public级别的属性
现在我想判断的是某个对象是否有某个属性,该属性却又是public级别的,请问要如何判断呢?

[解决办法]
procedure GetClassProperties(AClass: TClass; AStrings: TStrings);
var
PropCount, I: SmallInt;
PropList: PPropList;
PropStr: string;
begin
PropCount := GetTypeData(AClass.ClassInfo).PropCount;
GetPropList(AClass.ClassInfo, PropList);
for I := 0 to PropCount - 1 do
begin
case PropList[I]^.PropType^.Kind of
tkClass : PropStr := '[Class]';
tkMethod : PropStr := '[Method]';
tkSet : PropStr := '[Set] ';
tkEnumeration: PropStr := '[Enum] ';
else
PropStr := '[Field] ';
end;
PropStr := PropStr + PropList[I]^.Name;
PropStr := PropStr + ': ' + PropList[I]^.PropType^.Name;
AStrings.Add(PropStr);
end;
FreeMem(PropList);
end;

读书人网 >.NET

热点推荐