I just can't see what's wrong.
I didn't analyze what your are trying to do in your code, but it isn't correct for sure.
I.e.:
If i < sl.Count Then Inc(i);
Trail := Trim(sl[i]);
You are checking if variable 'i' is less then sl.Count.
Let's assume sl.Count is 100 and variable 'i' is 99. So you increase it to 100.
In next line you are accessing string list with sl[ i ]. Index here shouldn't be larger than 99.
And you have many of these increments in your code.
Maybe you should do it differently, something like this:
Inc(i);
If i >= sl.Count Then Exit; // or Break or whatever you do when you are at the end
Trail := Trim(sl[i]);
Edit: I didn't use code tags with variable 'i'.
That did it. I inserted your line 2 just after my line 135. I just left off the ">" and just used the "=".
Boom! Works like a charm!
Temp[x]:= Trim(sl[i]);
Memo1.Lines.Add('Hereafter lies i: ' + IntToStr(i) + '. And the count is: ' + IntToStr(sl.Count));
If i < sl.Count Then Inc(i); // This is line 135.
If i = sl.Count Then Exit;
Memo1.Lines.Add('After the Inc i: ' + IntToStr(i) + '. And the count is: ' + IntToStr(sl.Count));
Inc(x);
Let's assume sl.Count is 100 and variable 'i' is 99. So you increase it to 100.
In next line you are accessing string list with sl[ i ]. Index here shouldn't be larger than 99.
This was what hit me. I didn't even think about the
Exit.
Thank you dseligo!change all occurrences:If i < sl.Count Then Inc(i);
to:If i < sl.Count - 1 Then Inc(i);
I did that! Before I posted. That one really made it go crazy!