Tech Tutorials Database
GeekArticles Programming Delphi
 

TEnum<T> Simple generics Enum example

 
Author: cc.embarcadero.com
Category: Delphi
Comments (0)

a long time lover of Enumarated types, I created this simple example and use my TEnum<T> generic record with methods that wraps up the dirty details of a enumorated type and implicit class operators.It wraps a record with around a single field declared (Value) to be of the enumorated type. It uses implicit class operators bring the enumorated type back out to the surface, but also includes implicit class operators to allow getting and setting of the ordinal value, as wall as get and set by string. All with pretty much no code. (However it is a little visual the string format is friendly through the EnumToStr and StrToEnum functions in TEnum<T>.Small sample from the DPR code:type TJim = (jjHigh,jjLow,jjHello_There);var J: TEnum<TJim>; S: String; Strs: TStrings; I: Integer;begin Implicit assign of the friendly string J := implicit assign of enumorated name as J := string implicit ordinal assign J := 2; implicit assign of enumoratedtype J := jjHello_There; This uses casting to select the proper implicit conversion Output should be Add the enumorated type value to TStrings Strs.Add(J);end. I welcome your comments or feedback

Read More...




Sponsored Links




Read Next: Enhanced jpeg implementation



 

 

Comments



Post Your Comment:

Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe