The example is on RIP Tutorial - For loop using an enumeration
The code example will not be compiled in Embarcadero Delphi, gives out two error messages, one of them is:
"[dcc32 Error] EnumLoop.dpr(14): E2430 for-in statement cannot operate on collection type 'TWeekdays'"
program EnumLoop;
uses
TypInfo;
type
TWeekdays = (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday);
var
wd : TWeekdays;
begin
for wd in TWeekdays do
WriteLn(GetEnumName(TypeInfo(TWeekdays), Ord(wd)));
end.
The error explanation from docwiki Embarcadero
E2430 for-in statement cannot operate on collection type '%s' (Delphi) Go Up to Error and Warning Messages (Delphi) A for-in statement can only operate on the following collection types: Primitive types that the compiler recognizes, such as arrays, sets or strings Types that implement IEnumerable Types that implement the GetEnumerator pattern as documented in the Delphi Language Guide Ensure that the specified type meets these requirements.To make the example to work, replace with this line:
for wd := Low(TWeekdays) to High(TWeekdays) do
The example was tested in CodeGear Delphi 2007, Embarcadero Delphi 10.4.2 Sydney, Embarcadero Delphi 11.3 Alexandria
No comments:
Post a Comment