GeekArticles
Programming
Delphi
Programming
DelphiTEnum<T> Simple generics Enum example
a long time lover of Enumarated types, I created this simple example and use my TEnum&lt;T&gt; 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&lt;T&gt;.Small sample from the DPR code:type TJim = (jjHigh,jjLow,jjHello_There);var J: TEnum&lt;TJim&gt;; 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
Sponsored Links
Read Next: Enhanced jpeg implementation
Related Topics
Subscribe via RSS
Delphi
- A load of ASP.NET related tutorials, articles, tips and tricks!
- How to move PageControl's tabs using drag'n'drop
- Charts in database applications
- Creating Components Dynamically (at Run-Time)
- The role of the "AOwner" parameter in the Create constructor
- Creating a roll up form (with animation)
- Poll: Do you already have some experience with Delphi?
- Creating a database from Delphi code
- TMemoBar - T(Custom)Memo extender
- How to click-and-select a line in TMemo
