首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

怎么判断某个对象是否有某个属性(public级别的属性)

2012-02-28 
如何判断某个对象是否有某个属性(public级别的属性)GetPropInfo可以得到某个对象的Published出来的属性,但

如何判断某个对象是否有某个属性(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;

热点排行