2
votes
Vote UpVote

Fun Code of the Day #1

Delphi-losophy – unit uEnumConverter; interface type   TEnum = record   public     class function AsString<T>(aEnum: T): string; static;     class function AsInteger<T>(aEnum: T): Integer; static;   end; implementation uses       TypInfo     ; { TEnum } class function TEnum.AsString<T>(aEnum: T): string; begin   Result := GetEnumName(TypeInfo(T), AsInteger(aEnum)); end; class function TEnum.AsInteger<T>(aEnum: T): Integer; begin   case Sizeof(T) of     1: Result := pByte(@aEnum)^;     2: Result := pWord(@aEnum)^;     4: Result := pCardinal(@aEnum)^;   end; end; end. 
Favorite? Off-Topic? nickhodges@gmail.com @ 2015-04-17 16:42

Statistics

Visits: 1374
Votes: 2
Favorites: 0
Off-Topic: 0

Visits by Source

User Actions

Users who voted for this posting

NickHodges
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)