• Homework
  • Thirds
  • Upper Thirds
  • Fourth
  • Divisions
    • ICT
    • Computer Science
  • Fifth
  • Lower Sixth
  • Upper Sixth
    • Upper Sixth Theory
  • Blog
  • Careers
  • Unity
  • Networking
computinglesson.com

Guide to Arrays in Delphi

What is an Array?

When we start programming we imagine variables as little boxes which can contain one value and only one value.  

Using the same metaphor, Arrays are like groups of boxes.  Like variables, Arrays have a name, and each individual box in the group is referred to with a number.
Picture
Picture
Arrays are very useful because they allow us to pick out bits of data by using a number.

The number is the index of the array.

How do I make one?

Create an array in Delph like this:
myArray : Array[0..2] of string;
Each 'box' in an array is called an element
The elements are referred to with the index

The numbers in the array definition above tell Delphi how many elements to create and where to start numbering them.

Two dimensional arrays

Picture
Two dimensional arrays are like tables.  You can use them to store multiple items of data - for example multiple answers.  To make one it's just the same as for a one dimensional array, except that you tell Delphi to give it two number ranges:
myArray : Array[0..2,0..1] of string;
Here we've said that there are three rows, numbered 0,1 and 2 - and two columns numbered 0 and 1.  To find Gishean's age we indicate which array element we want like this;
myResult = myArray[2,1]
.. which says 'go to row with index number 2 and column with index number 1.
Powered by Create your own unique website with customizable templates.