AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

RTTI Enum von Propertys?

Ein Thema von Mavarik · begonnen am 16. Jan 2015 · letzter Beitrag vom 17. Jan 2015
Antwort Antwort
Seite 2 von 2     12   
Benutzerbild von Mavarik
Mavarik

Registriert seit: 9. Feb 2006
Ort: Stolberg (Rhld)
4.126 Beiträge
 
Delphi 10.3 Rio
 
#11

AW: RTTI Enum von Propertys?

  Alt 17. Jan 2015, 11:13
Delphi-Quellcode:
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;
Das ist schon gut...

Aber was ist wenn ich so etwas habe?

Delphi-Quellcode:
Type
    TFooBasis = class
       private
          FInt : Integer;
       public
          property ParamInt : Integer read FInt;
    end;

    TFoo = class
       private
         FBool : Boolean;
       public
         Property ParamBool : Boolean read FBool;
    end;

var
    FooBasis : TFooBasis;
begin
   FooBasis := TFoo.Create;

   GetAllPropertys(FooBasis);
end;
Komme ich da auch an die Propertys?

Mavarik
  Mit Zitat antworten Zitat
Benutzerbild von Stevie
Stevie

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

AW: RTTI Enum von Propertys?

  Alt 17. Jan 2015, 12:22
Delphi-Quellcode:
procedure GetAllProperties(obj: TObject);
var
  context: TRttiContext;
  properties: TArray<TRttiProperty>;
  propertyIterator: TRttiProperty;
begin
  properties := context.GetType(obj.ClassInfo).GetProperties();
  for propertyIterator in properties do
    WriteLn(propertyIterator.Name);
end;
Stefan
“Simplicity, carried to the extreme, becomes elegance.” Jon Franklin

Delphi Sorcery - DSharp - Spring4D - TestInsight
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.142 Beiträge
 
Delphi 12 Athens
 
#13

AW: RTTI Enum von Propertys?

  Alt 17. Jan 2015, 18:33
Aber was ist wenn ich so etwas habe?
Einen Cmpiler-Fehler.


Und wenn man es dennoch schaft das da reinzubekommen, dann holt man da natürlich die RTTI-Infos aus der Instanz und nicht aus dem Variablentyp.

FooBasis.ClassInfo / FooBasis.ClassName
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 2     12   


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 20:45 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz