I like [Wayback/Archive] enumerated type a lot.
The allow you to perfectly describe what the members of such a type actually mean, much more readable than a bunch of integer constants!
Given an enumerated type like TTraphicLightColors
type
TTraphicLightColors = (Red, Orange, Green);
I always wondered why – since the for ... in
statement was added to the [Wayback/Archive] structured statements part of the Delphi language – it is not possible to use a for … in statement like the this:
</span>
<pre>var
TraphicLightColor: TTraphicLightColors;
begin
try
for TraphicLightColor in TraphicLightColor do
ShowValueAsTraphicLightColor(Ord(Value));
// [DCC Error] EnumerationEnumeratorDemoProcedures.dpr(63): E2430 for-in statement cannot operate on collection type 'TTraphicLightColors'
end;
Somehow, for ... in
[Wayback/Archive] expects a collection type.
A request for [WayBack/Archive] the for … in do on enumerated types compiler feature is in QC, but it is closed with reason “Won’t do”.
Back in Delphi 2007, I tried working around this by writing a type implementing the GetEnumerator
pattern myself, but got [WayBack/Archive] Internal Errors when compiling anything but the most basic sample.
Until today, where I found how I could get that most basic sample to work!
It is an example on how you could implement this: it is research, so you decide if you find the result practical enough to use yourself.
Read the rest of this entry »
Like this:
Like Loading...