Einzelnen Beitrag anzeigen

Der schöne Günther

Registriert seit: 6. Mär 2013
6.110 Beiträge
 
Delphi 10 Seattle Enterprise
 
#6

AW: RTTI Enum von Propertys?

  Alt 16. Jan 2015, 12:13
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

Code:
Value
RefCount
Welche Magie steckt hier dahinter?
  Mit Zitat antworten Zitat