Open kjpowerworld opened 4 years ago
@kjpowerworld I can't confirm it compiles. I'm getting an error in Delphi 10.3.3:
var
S: TList<TObject>;
A: TForm;
begin
for TObject(A) in S do
end;
[dcc32 Error] Unit7.pas(30): E1019 For loop control variable must be simple local variable
it should be:
for var item:TObject in S do
@RomanYankovsky You know what, I realized what I'm seeing...I think it's something goofy with list enumerators over lists of pointers combined with typecasting that does nothing. So if I take your example code and change it to this:
var
S: TObjectList;
A: TForm;
begin
for TForm(A) in S do
end;
it compiles. Obviously in this case the TForm()
typecast doesn't achieve anything, but it is syntax that does compile.
Changing from QualifiedIdentifier to Variable allows the for-in loop to have this syntax:
for TSomeType(VarName) in Collection do
So then the VarName can be of a different type than the Collection item type and be typecast to match the item type. The above syntax compiles in Delphi.