获得属性(rtti)
1: procedure GetBaseClassPro(AClass : TObject;Astrings : TStrings); //获得属性信息2: var
3: NumPro : integer; //用来记录事件属性的个数
4: Pplst : PPropList; //存放属性列表
5: Classtypeinfo : PTypeInfo;6: classDataInfo: PTypeData;7: i : integer;8: begin
9: Classtypeinfo := AClass.ClassInfo;10: classDataInfo := GetTypeData(Classtypeinfo);11: if classDataInfo.PropCount <> 0 then12: begin
13: //分配空间
14: GetMem(Pplst,sizeof(PpropInfo)*classDataInfo.PropCount);15: try16: //获得属性信息到pplst
17: GetPropInfos(AClass.ClassInfo,Pplst);18: for I := 0 to classDataInfo.PropCount - 1 do19: begin
20: if Pplst[i]^.PropType^.Kind <> tkMethod then21: //这里过滤掉了事件属性
22: Astrings.Add(Format('%s:%s',[Pplst[i]^.Name,Pplst[i]^.PropType^.Name]));23: end;
24: //获得事件属性
25: NumPro := GetPropList(AClass.ClassInfo,[tkMethod],Pplst);26: if NumPro <> 0 then27: begin
28: //给列表添加一些标志
29: Astrings.Add('');30: Astrings.Add('-----------EVENT-----------');31: Astrings.Add('');32: for i := 0 to NumPro - 1 do //获得事件属性的列表33: Astrings.Add(Format('%s:%s',[Pplst[i]^.Name,Pplst[i]^.PropType^.Name]));34: end;
35: finally36: FreeMem(Pplst,sizeof(PpropInfo)*classDataInfo.PropCount);37: end;
38: end;
39: end;