Einzelnen Beitrag anzeigen

Benutzerbild von Uwe Raabe
Uwe Raabe

Registriert seit: 20. Jan 2006
Ort: Lübbecke
11.021 Beiträge
 
Delphi 12 Athens
 
#8

AW: Geerbter Getter für lokale Objekt-Konstante?

  Alt 23. Jul 2020, 17:26
Dann lass den TRTTIHelper ganz weg und mach das direkt in dem FuncInfoAttribute:
Delphi-Quellcode:
type
  FuncInfoAttribute = class(TCustomAttribute)
  private
    FGL: string;
    Fn_Var: Integer;
  public
    constructor Create(AGL: string; An_Var: Integer);
    class function FindAttribute(Source: TClass): FuncInfoAttribute;
    property GL: string read FGL;
    property n_Var: Integer read Fn_Var;
  end;

class function FuncInfoAttribute.FindAttribute(Source: TClass): FuncInfoAttribute;
var
  context: TRttiContext;
  myType: TRttiType;
  attr: TCustomAttribute;
  attributes: TArray<TCustomAttribute>;
begin
  Result := nil;
  context := TRttiContext.Create;
  myType := context.GetType(Source);
  if myType <> nil then begin
    attributes := myType.GetAttributes;
    for attr in attributes do begin
      if attr is FuncInfoAttribute then begin
        Result := FuncInfoAttribute(attr);
        Break;
      end;
    end;
  end;
end;
In den Gettern musst du dann die FindAttribute-Zeile so schreiben:
Delphi-Quellcode:

  attr := FuncInfoAttribute.FindAttribute(ClassType);
Uwe Raabe
Certified Delphi Master Developer
Embarcadero MVP
Blog: The Art of Delphi Programming
  Mit Zitat antworten Zitat