AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

Geerbter Getter für lokale Objekt-Konstante?

Ein Thema von Andreas13 · begonnen am 22. Jul 2020 · letzter Beitrag vom 24. Jul 2020
 
Benutzerbild von Uwe Raabe
Uwe Raabe

Registriert seit: 20. Jan 2006
Ort: Lübbecke
11.629 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
 

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:10 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz