Thank you all for the replies. For my own purposes, TRon's suggested workaround is the best option, since it keeps everything within a single line of code. I'll be using that until the issue itself is fixed:
[...]
Another solution/workaround:
uses
types;
var
a : String;
begin
for a in TStringDynArray.Create('pear','apple','banana','pineapple','orange')
do writeLn(a);
end.
This looks like iteration of a set of strings. I thought things in set had to be ordinal values? Did something change?
[...]
I might be using the wrong terminology. I'm a self-taught amateur and not really on the up-and-up.
Is there any good reason to use for.. in to iterate through an array instead of using a for loop with index? I’m only familiar with using for.. in in the context of things like sets where the number of items is unknown. I’ve also seen it used for fields in an sql dataset.
There are a few reasons, but the specific scenario that prompted me to open this thread is that such a for-in loop is the most compact way to add strings to a TStringList on the fly for testing and debugging purposes. If I used a for-to loop, I'd have to define my constant array somewhere else, which can't be done within in the vicinity of my loop, which means I'd have to jump back and forth a lot during testing. Writing the array as part of a for-in loop makes it possible to have everything in one place.
Aside from the specific scenario of having the array defined within the loop, there are sometimes very simple loops where the index serves no purpose beyond retrieving the item at that index, so a for-in loop performs that step implicitly and is easier to read and write. Compare:
for item in MyArray do SomeProcedure(item);
versus
for idx:=Low(MyArray) to High(MyArray) do SomeProcedure(MyArray[idx]);