I hereby declare this week as the week of the enumerator. ;-)
Hallvard Vassbotn started this week with an excellent post on using enumerators patterns on your own collections. You should really give this high School enumeration stuff, a read!
The .NET Framework it self offers a lot of basic functionality for enumerators. It is friday so let's take a look on some basics here:
Sometimes it is necessary to let a user pick a value from a enumerator type. For example you want the user to pick some property value of a component, which is enumerator. You could, of course, fill a combox with string values by hand (keeping the order), but in future releases the list could extended, having you to alter your code.
Looping an enumerator
It is easier then to simply loop through the enumerator type. Update! In Delphi win32 this is not possible. This is false! Uli commented that it can in Delphi Win32!, using the Typinfo unit. (See the code in the comments)
In .NET however this is possible using the Enum.GetNames method.
In C# you code looks like this:
foreach ( string s in Enum.GetNames(typeof(SeriesChartType)) )
the equivalent code in Delphi .NET is:
for s in Enum.GetNames(TypeOf(SeriesChartType)) do begin
Exists a value?
Check if a enumerator value exists in a enumerator type with the IsDefined method.
Delphi .NET code:
s := 'Point';
if Enum.IsDefined(TypeOf(SeriesChartType), s) then
Conclusion, the .NET framework Enum class, which is the base class for all the enumerator types, adds valueable methods to the basic enumerator types.
More information can be found on MSDN here.