Arrays: Difference between revisions
Content added Content deleted
Line 1,641: | Line 1,641: | ||
procedure TForm1.Button1Click(Sender: TObject); |
procedure TForm1.Button1Click(Sender: TObject); |
||
var |
var |
||
StaticArray: array[ |
StaticArray: array[1..10] of Integer; // static arrays can start at any index |
||
DynamicArray: array of Integer; |
DynamicArray: array of Integer; // dynamic arrays always start at 0 |
||
StaticArrayText, |
StaticArrayText, |
||
DynamicArrayText: string; |
DynamicArrayText: string; |
||
ixS, ixD: Integer; |
|||
begin |
begin |
||
// Setting the length of the dynamic array the same as the static one |
// Setting the length of the dynamic array the same as the static one |
||
SetLength(DynamicArray, Length(StaticArray)); |
SetLength(DynamicArray, Length(StaticArray)); |
||
// Asking random numbers storing into the static array |
// Asking random numbers storing into the static array |
||
for |
for ixS := Low(StaticArray) to High(StaticArray) do |
||
begin |
begin |
||
StaticArray[ |
StaticArray[ixS] := StrToInt( |
||
InputBox('Random number', |
InputBox('Random number', |
||
'Enter a random number for position', |
'Enter a random number for position', |
||
IntToStr( |
IntToStr(ixS))); |
||
end; |
end; |
||
// Storing entered numbers of the static array in reverse order into the dynamic |
// Storing entered numbers of the static array in reverse order into the dynamic |
||
ixD := High(DynamicArray); |
|||
⚫ | |||
for ixS := Low(StaticArray) to High(StaticArray) do |
|||
⚫ | |||
for lcv := 0 to Pred(Length(StaticArray)) do |
|||
begin |
begin |
||
DynamicArray[ixD] := StaticArray[ixS]; |
|||
Dec(ixD); |
|||
⚫ | |||
end; |
|||
⚫ | |||
StaticArrayText := ''; |
|||
⚫ | |||
StaticArrayText := StaticArrayText + IntToStr(StaticArray[ixS]); |
|||
DynamicArrayText := ''; |
|||
for ixD := Low(DynamicArray) to High(DynamicArray) do |
|||
⚫ | |||
end; |
end; |
||
// Displaying both arrays (#13#10 = Carriage Return/Line Feed) |
// Displaying both arrays (#13#10 = Carriage Return/Line Feed) |