AGB  ·  Datenschutz  ·  Impressum  







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

Generisches ToString für Enumerations

Ein Thema von s.h.a.r.k · begonnen am 30. Apr 2011 · letzter Beitrag vom 3. Mai 2011
 
Benutzerbild von s.h.a.r.k
s.h.a.r.k

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

AW: Generisches ToString für Enumerations

  Alt 30. Apr 2011, 15:34
Ha, ich habs

Delphi-Quellcode:
TLog = record
  class procedure AddEnum<T>(V: T); static;
end;

class procedure TLog.AddEnum<T>(V: T);
begin
  Writeln(GetEnumName(TypeInfo(T), PByte(@V)^));
end;
Der Tipp von himitsu war gut. Jetzt muss ich nur noch testen, ob das auch immer passen sollte. In meinen Fall passts jedenfalls. Aber man kann ja auch gewisse Werte für die Enum-Elemente definieren. Melde mich gleich wieder.

@daywalker: klar, so gehts auch

-- EDIT: So, habe mich jetzt nochmals ein wenig mit diesen Enumerations befasst und bin auf ein weiteres Problem gestoßen, welches dieses Zitat auf den Punkt bringt:
Zitat von http://delphi.wikia.com/wiki/GetEnumValue_Routine:
Be aware that Typeinfo will be lost when the enumeration is given different ordinal values. With the next enumeration example it's not possible to use GetEnumValue and will result in 'E2134 Type 'TTestType' has no type info'
Schade, aber man kann daran wohl nix ändern.
»Remember, the future maintainer is the person you should be writing code for, not the compiler.« (Nick Hodges)

Geändert von s.h.a.r.k (30. Apr 2011 um 16:07 Uhr)
  Mit Zitat antworten Zitat
 


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 13:57 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