I noticed something strange when using interfaces with a for-in-loop. (I had used it as a way to simulate block scoped variables)
Let IFoo be an interface that can be used in a for-in statement (assume the enumerator does not keep a reference to the IFoo). Let makeFoo be a function that returns a new IFoo (actually a new one, not the same as before).
Then e.g.:
for x in makeFoo do
writeln(x)
will enumerate all the x in the IFoo.
Afterwards,
after the for-in-statement, the IFoo will be destroyed.
But when we write
for x in makeFoo do begin
makeFoo;
writeln(x);
end
The second call to makeFoo will destroy the IFoo from the first call.
Isn't this very inconsistent? Either the first foo should be really temporary and be destroyed after the enumerator is created; or kept till the end the loop.