Today I met a very strange mistake.
I have the following code:
var i: integer;
...
for i := 0 to FileNames.Count - 1 do
begin
ShowMessage(IntToStr(i) + ' from ' + IntToStr(FileNames.Count - 1));
FileName := FileNames[i];
...
end;
ShowMessage('all');
There is one item in the FileNames list. So, I believe that the loop will be executed once, and I see
0 from 0
all
This is what I have done thousands of times :). But in this case, I see the second iteration of the loop when code optimization is enabled.
0 from 0
1 from 0
all
Without a code optimization loop, iterates to the right. At the moment, I don’t even know the direction to move with this problem (and the upper cycle does not change, yes).
Therefore, any suggestion will be very useful. Thank.
I am using the Delphi 2005 compiler (Upd2).
Miamy source
share