Guter Einwand.
Delphi-Quellcode:
program Project16;
{$APPTYPE CONSOLE}
{$R *.res}
uses System.SysUtils, System.Rtti;
type
TObjectHelper =
class helper
for TObject
protected
function getValue(): Integer;
public property
Value: Integer
read getValue;
end;
{ TObjectHelper }
function TObjectHelper.getValue(): Integer;
begin
Result := 42;
end;
procedure justRttiThings();
var
context: TRttiContext;
rttiType: TRttiType;
properties: TArray<TRttiProperty>;
propertyIterator: TRttiProperty;
begin
context := TRttiContext.Create();
properties := context.GetType( TypeInfo(TObjectHelper)).GetProperties();
for propertyIterator
in properties
do
WriteLn(propertyIterator.
Name);
end;
begin
try
justRttiThings();
except
on E:
Exception do
Writeln(E.ClassName, '
: ', E.
Message);
end;
readln;
end.
ergibt
Welche Magie steckt hier dahinter?