Mega Code Archive

 
Categories / Delphi / Examples
 

Safe array looping

An Object Pascal array is a group elements of a similar type with an index range. How do you access every array element without looking back in your code for the correct lower and upper index values? The Low and High functions ensure you access each element, as illustrated in this example code: var MyArray : array[2..11] of integer; Position : integer; begin for Position := Low(MyArray) to High(MyArray) do MyArray[Position] := 0; end;