Einzelnen Beitrag anzeigen

Benutzerbild von s.h.a.r.k
s.h.a.r.k

Registriert seit: 26. Mai 2004
3.159 Beiträge
 
#5

Re: [RTTI] Setter und Getter einer Property

  Alt 31. Mär 2010, 21:46
Wie folgt kann man den Pointer auf die Getter- und Setter-Methode einer Property ermitteln.

Delphi-Quellcode:
var
  rContext : TRttiContext;
  rType : TRttiType;
  rProperty : TRttiProperty;
  rPropInfo : PPropInfo;
  pt : Pointer;
begin
  rContext := TRttiContext.Create();
  try
    rType := rContext.GetType(Self.ClassType);
    for rProperty in rType.GetDeclaredProperties do
    begin
      rPropInfo := TRttiInstanceProperty(rProperty).PropInfo;

      // Pointer auf Setter-Methode
      pt := rPropInfo.GetProc;

      // Pointer auf Getter-Methode
      pt := rPropInfo.GetProc;
      
      { ... }

    end;
  finally
    rContext.Free();
  end;
end;
»Remember, the future maintainer is the person you should be writing code for, not the compiler.« (Nick Hodges)
  Mit Zitat antworten Zitat