Your welcome "What I can do" and I'm glad to see that you were able to solve your issue.
followed by WTF moments
It is another way of iterating an array that doesn't require to declare a separate index iterator.
In practice you can do that for any array (enumerable type), e.g:
type
TFoo = record
Bar : string;
end;
TFooArray : array of TFoo;
var
Foo : TFoo;
FooArray : TFooArray; // array is empty, needs to be "filled" before the routine below actually outputs something
begin
for Foo in FooArray
do writeln(Foo.Bar)
end;
Do note that in this case the iterator is a copy of the record and not the record itself. That means that changing any of the fields of the iterator is not actually 'stored' in the array.
See also
for..do documentationThe enumerable expression can be one of five cases:
- An enumeration type identifier. The loop will then be over all elements of the enumeration type. The control variable must be of the enumeration type.
- A set value. The loop will then be over all elements in the set, the control variable must be of the base type of the set.
- An array value. The loop will be over all elements in the array, and the control variable must have the same type as an element in the array. As a special case, a string is regarded as an array of characters.
- An enumerable class, object, or extended record instance. This is an instance of any structured type that supports the IEnumerator and IEnumerable interfaces. In this case, the control variable’s type must equal the type of the IEnumerator.GetCurrent return value.
- Any type for which an enumerator operator is defined. The enumerator operator must return a structured type that implements the IEnumerator interface. The type of the control variable’s type must equal the type of the enumerator’s GetCurrent return value type.
interesting...at cursor writestr
WriteStr works, as the documentation mentions, similar as write (or writeln but withouth the newline character added).
Meaning that whatever type that can be written by write works exactly the same as when using WriteStr.
The (only) difference is that the first parameter of WriteStr is the string that everything is written to (instead of writing the generated text to the standard output handle).
If wanted it is possible to use writestr to 'extend' the string like:
var
s : string;
begin
writestr(s, '');
writestr(s, s, 'Foo'); // s contains "Foo"
writestr(s, s, 'bar'); // s contains "Foobar"
end;
If there are any (other) questions then feel free to ask.
Perhaps the above ramblings might be useful to someone.