Changing the for-in loop variable expectation#304
Open
kjpowerworld wants to merge 1 commit intoRomanYankovsky:masterfrom
Open
Changing the for-in loop variable expectation#304kjpowerworld wants to merge 1 commit intoRomanYankovsky:masterfrom
kjpowerworld wants to merge 1 commit intoRomanYankovsky:masterfrom
Conversation
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.
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 |
|
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: it compiles. Obviously in this case the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.