Mega Code Archive

 
Categories / Delphi / Examples
 

Twodarrays

TWO-DIMENSIONAL ARRAY SYNTAX Richard November '98 Example 1. (The simplest). const maxX = 1024; maxY = 780; var pixelArray[1..maxX, 1..maxY] of Integer; elements accessed like this: pixelArray[x,y] := 69; (where x and y are integers); *********************************************************** Example 2. type TCoord = record X: Integer; Y: Integer; end; var CoordArray: array[0..100] of TCoord; elements accessed like this: CoordArray[n].X := 0; CoordArray[n].Y := 0; (where n is an integer) *********************************************************** Example 3. This one's interesting because the array indeces are a character and an integer: const last_row = 'J'; last_column = 10; type TSeat = record seat_number: String; customer_name: String; booked: Boolean; end; type TSeatArray = array ['A'..last_row, 1..last_column] of TSeat; var SeatArray : TSeatArray; elements accessed like this: SeatArray[row,column].customer_name := 'John Smith'; (where row is a character in the range A to J and column is an integer in the range 1 to 10)