Here some declared variables:
procedure TFormMain.ButtonStartClick(Sender: TObject); var //Local variables declarations LocalInteger : integer; S1,S2 : string; i : integer; Players : array [1..9] of string; //Static array UnlimitedPlayers : array of string; //Dynamic array
Variables are all local, in the internal scope of procedure - associated to the button click - which only can manage them.
What we find?
An integer (positive and negative integer numbers), a string, an integer again, and two arrays. Interesting!
In just a moment we have met two two grouping structures:
- String: an ordered collection of characters.
- Array: an ordered collection of data of same nature.
Maybe you've noticed string are a special kind of arrays. Strings are so important that any evoluted programming language has sofisticated ways to managed them apart from any other structure.
Array can obviously contain chars (short for characters), but also other types: integer, float (numbers with decimal point), and even arrays containing other types, even arrays again!
The main point is an array can host only one type, according to the one in the declaration.
[An array is also called a vector, or a 1-Dimension matrix, from algebric concepts; array of array of... are matrices]
It's time to repropose the initial picture.
In few words...
if we declare an array of five integers with the name A, compiler reserves five boxes referring all to A and numbered from 0 to 4.
By assigning values to A we progressively and orderly put them into the array: in this case the double question marks is substituted by the first integer value.
Do things change with strings?
First of all a string, if not specified, can contain up to max 255 chars (from 1 to 255) with the 0-th occupied instead by an integer which indicates the string's length.
So if we write A := 'okay'; then we have A=4, A= o, A= k, A= a and A= y.
[Attention: RAM locations have fixed dimension - 32 bits are classical - But while a char requires an amount of bits (8), any other type wants more bits; so boxes are to be intended logically, not physically]
Well... while we always know string's maximum length, arrays present a little major flexibility.
Look at the code: they are both arrays of strings, but while the first Players has dimension 10 (that's ten strings ordered from 0 to 9), the second UnlimitedPlayers has potentially no limits (from 0 to infinite). The only one is the available memory.
The first is a static array and the second is dynamic.