Author: Jonas Bilinkevicius
How can I propogate through an object's published properties and extract an actual
class reference in order to perform operations like: if GiveProperty is
TSomeObjectType then do something?
Answer:
1 function GetFontProp(anObj: TObject): TFont;
2 var3 PInfo: PPropInfo;
4 begin5 {Try to get a pointer to the property information for a 6 property with the name 'Font'.7 TObject.ClassInfo returns a pointer to the RTTI table, which we need to pass8 to GetPropInfo}9 PInfo := GetPropInfo(anObj.ClassInfo, 'font');
10 Result := nil;
11 if PInfo <> nilthen12 {found a property with this name, check if it has the correct type}13 if (PInfo^.Proptype^.Kind = tkClass) and14 GetTypeData(PInfo^.Proptype^)^.ClassType.InheritsFrom(TFont) then15 Result := TFont(GetOrdProp(anObj, PInfo));
16 end;