Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.

ID: 27397, TEnum<T> Simple generics Enum example

by Jim Ferguson Email: Anonymous

If you use GetEnumName than this is for you! Never have to worrie about converting enumorations again now that generics are here.
Download Details
FTP  download also available
CDN Login Required to Download. (You will be redirected to the login page if you click on the Download Link)
To download this, you must have registered:
A free membership

For Delphi, Version 12.0  to 14.0 531 downloads
Copyright: No significant restrictions

Size: 2,089 bytes
Updated on Tue, 13 Oct 2009 08:48:15 GMT
Originally uploaded on Fri, 09 Oct 2009 12:35:07 GMT
SHA1 Hash: E41FE79DA220B7A8CC8B0C2D71DC89FE6331A64A
MD5 Hash: 73863B63B431FC13E854A5B8BB77F507

    Explore the files in this upload

I'm 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 basic'ish)

Even the string format is friendly through the EnumToStr and StrToEnum functions in TEnum<T>.

Small sample from the DPR code:

TJim = (jjHigh,jjLow,jjHello_There);
J: TEnum<TJim>;
S: String;
Strs: TStrings;
I: Integer;
// Implicit assign of the friendly string
J := 'Hello There';

// implicit assign of enumorated name as
J := 'jjHello_There'; 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 'Hello There(2)'

// Add the enumorated type value to TStrings

I welcome your comments or feedback

   Latest Comments  View All Add New

Move mouse over comment to see the full text

Could not retrieve comments. Please try again later.

Server Response from: ETNACDC03