Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing the for-in loop variable expectation #304

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kjpowerworld
Copy link
Contributor

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.

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.
@RomanYankovsky
Copy link
Owner

@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

@jkour
Copy link

jkour commented May 25, 2020

it should be:

for var item:TObject in S do

@KyleJ61782
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants