Unusually, I'm not looking for a solution to a problem (that is normally why I start a thread!) I have solved the issue but thought that it, the reason and the solution might be of interest.
I've been using my accouning package, originally written under Lazarus 1.6, for some years with very few problems. Earlier this year I had a problem with a new project which resulted in my updating to Lazarus 2.2.0 so naturally 'tweaks' to my existing programs are now also done under this.
Most of my invoices are single line items, three lines are unusual so I had allowed for a max of 5 which I think I have used less than 10 times in 30 years. Today I had to raise an invoice which has 5 lines and is the first time since using Laz 2.2.
Everything was 'normal' until I came to [Print] the invoice, whereupon I had a "201 - Range Check Error" !!! - - - - when I ran the project with de-bugging it seemed most peculiar to find the error was fired by a simple [ inc(c) ] instruction. The particular section of code was :
While (Invoice.item[c].Desc > '') and (c < 6) Do
begin
[...]
inc(c)
end;
Under Laz 1.6 this was perfectly acceptable but it seems that Laz 2.2 is not happy at all
Compiling with 'Range Checking OFF' did not solve it.
The problem is of course that [Invoice.items] is declared as an array of 5 elements so naturally [c] can never be 6 - though why it fired the error at 'inc(c)' rather than 'While (Invoice.item[c].Desc ...' is still a mystery to me.
My solution was to introduce a new Boolean ('Done') and modify the proc thus :
Done := false;
While (Invoice.item[c].Desc > '') and (not Done) Do
begin
[...]
if c < 5 then
inc(c)
else
Done := True;
end;
I hope this explanation may be of some small benefit.