[fpc-pascal] Access Violation When SetLength(DynArray, Value)

James Richters james.richters at productionautomation.net
Fri Sep 9 14:58:34 CEST 2022

I only recently learned about using Low() and High() and it is so much nicer
For I:= 0 to Length(MyArray)-1 Do

That I actually went though all my code replacing the Length() - 1's with

I still end up with a lot of 
Every time I want to add one more thing to the array.

Almost all of my  dynamic arrays do this, because I can only add one thing
at a time to the array... and the reason I wanted it to be dynamic in the
first place.  

Is there some nifty way to increase a dynamic array by 1 that is more
Inc(MyArray); would sure be nice


>To avoid this kind of error you can use
>   for i:= 0 to High(Rails) do
>or even
>    for i:= Low(Rails) to High(Rails) do

More information about the fpc-pascal mailing list