5
votes
Vote UpVote

Generics, Enumerated types and ordinal values

Lars Fosdal – I wish this was a solution post, but it is a frustration post. I trying to figure out how I can use Ord() to convert an enumerated type to integer or cast an integer to an enumerated type using generics type arguments?uses SysUtils, TypInfo;type TEnumGen = class class function Name(const Enum:TEnumType):String; end;class function TEnumGen.Name(const Enum: TEnumType): String;begin Result := Format('%s.%s', [GetTypeName(TypeInfo(TEnumType)), GetEnumName(TypeInfo(TEnumType), Ord(Enum)) ]);end;Unfortunately there is no "enum" delimiter that can be used to tell the compiler ...
Favorite? Off-Topic? Lars Fosdal @ 2011-04-08 20:02

Statistics

Visits: 1361
Votes: 5
Favorites: 0
Off-Topic: 0

Visits by Source

User Actions

Users who voted for this posting

Alister Christie
ket555
Ravaut123
Tier777
Wouter
Subscribe:
Contact us to advertise on DelphiFeeds.com

Community Links

Torry Firebird News

Sponsor

 
Please login or register to use this functionality.
(click on this box to dismiss)