Einzelnen Beitrag anzeigen

Benutzerbild von Stevie
Stevie

Registriert seit: 12. Aug 2003
Ort: Soest
4.012 Beiträge
 
Delphi 10.1 Berlin Enterprise
 
#2

AW: Rtti und Attribute in Delphi 2010

  Alt 25. Aug 2011, 10:01
Attribute sind Teil der RTTI, von daher musst du sie auch darüber auslesen.

Delphi-Quellcode:
var
  ctx: TRttiContext;
  t: TRttiType;
  m: TRttiMethod;
  a: TCustomAttribute;
begin
  t := ctx.GetType(TMyClass);
  m := t.GetMethod('MyProc');
  for a in m.GetAttributes do
  begin
    if a is MyAttribute then
    begin
      ShowMessageFmt('Name: %s, age: %d', [MyAttribute(a).Name, MyAttribute(a).Age]);
    end;
  end;
end;
Stefan
“Simplicity, carried to the extreme, becomes elegance.” Jon Franklin

Delphi Sorcery - DSharp - Spring4D - TestInsight
  Mit Zitat antworten Zitat