Using the Typinfo unit, it is easy to enumerate properties as seen in the following snippet:
procedure TYRPropertiesMap.InitFrom(AClass: TClass; InheritLevel: Integer = 0);
var
propInfo: PPropInfo;
propCount: Integer;
propList: PPropList;
propType: PPTypeInfo;
pm: TYRPropertyMap;
classInfo: TClassInfo;
ix: Integer;
begin
ClearMap;
propCount := GetPropList(PTypeInfo(AClass.ClassInfo), propList);
for ix := 0 to propCount - 1 do
begin
propInfo := propList^[ix];
propType := propInfo^.PropType;
if propType^.Kind = tkMethod then
Continue; // Skip methods
{ Need to get GetPropInheritenceIndex to work
if GetPropInheritenceIndex(propInfo) > InheritLevel then
Continue; // Dont include properties deeper than InheritLevel
}
pm := TYRPropertyMap.Create(propInfo.Name);
FList.Add(pm);
end;
end;
However, what I need is to figure out the exact class from which each property inherits. For example in TControl, the Tag property comes from TComponent, which gives it an inheritance depth of 1 (0 being a property declared in TControl itself, such as Cursor).
Calculating the inheritance depth is easy if I know which class first defined the property. For my purposes, wherever a property first gained published visibility is where it first appeared.
I am using Delphi 2007. Please let me know if more detail is required. All help will be appreciated.