You can use this function to get the name of your attribute from this property (you wrote it in a minute, it may take some optimization):
uses SysUtils, Rtti, TypInfo; function GetPropAttribValue(ATypeInfo: Pointer; const PropName: string): string; var ctx: TRttiContext; typ: TRttiType; Aprop: TRttiProperty; attr: TCustomAttribute; begin Result := ''; ctx := TRttiContext.Create; typ := ctx.GetType(ATypeInfo); for Aprop in typ.GetProperties do begin if (Aprop.Visibility = mvPublished) and (SameText(PropName, Aprop.Name)) then begin for attr in AProp.GetAttributes do begin if attr is MyAttr then begin Result := MyAttr(attr).Name; Exit; end; end; Break; end; end; end;
Name it as follows:
sAttrName:= GetPropAttribValue(obj.ClassInfo, lPropName);
So, if this function returns an empty string, it means that the property is not marked MyAttr, and then you need to use "lPropInfo ^ .Name".
Linas
source share