I am currently using this code, but does not list anything. What I'm missing?
program ListAttrs;
{$APPTYPE CONSOLE}
uses
Rtti,
SysUtils;
type
TPerson = class
private
FName: String;
FAge: Integer;
public
[NonEmptyString('Must provide a Name')]
property Name : String read FName write FName;
[MinimumInteger(18, 'Must be at least 18 years old')]
[MaximumInteger(65, 'Must be no older than 65 years')]
property Age : Integer read FAge write FAge;
end;
procedure test;
var
ctx : TRttiContext;
lType : TRttiType;
lAttribute: TCustomAttribute;
lProperty : TRttiProperty;
begin
ctx := TRttiContext.Create;
lType := ctx.GetType(TPerson);
for lProperty in lType.GetProperties do
for lAttribute in lProperty.GetAttributes do
Writeln(lAttribute.ToString);
end;
begin
try
Test;
Readln;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.