RosettaCodeData/Task/Arrays/Delphi/arrays.delphi

37 lines
1.4 KiB
Text
Raw Permalink Normal View History

2013-04-10 16:57:12 -07:00
procedure TForm1.Button1Click(Sender: TObject);
var
2018-06-22 20:57:24 +00:00
StaticArray: array[1..10] of Integer; // static arrays can start at any index
DynamicArray: array of Integer; // dynamic arrays always start at 0
2013-04-10 16:57:12 -07:00
StaticArrayText,
DynamicArrayText: string;
2018-06-22 20:57:24 +00:00
ixS, ixD: Integer;
2013-04-10 16:57:12 -07:00
begin
// Setting the length of the dynamic array the same as the static one
SetLength(DynamicArray, Length(StaticArray));
// Asking random numbers storing into the static array
2018-06-22 20:57:24 +00:00
for ixS := Low(StaticArray) to High(StaticArray) do
2013-04-10 16:57:12 -07:00
begin
2018-06-22 20:57:24 +00:00
StaticArray[ixS] := StrToInt(
2013-04-10 16:57:12 -07:00
InputBox('Random number',
'Enter a random number for position',
2018-06-22 20:57:24 +00:00
IntToStr(ixS)));
2013-04-10 16:57:12 -07:00
end;
// Storing entered numbers of the static array in reverse order into the dynamic
2018-06-22 20:57:24 +00:00
ixD := High(DynamicArray);
for ixS := Low(StaticArray) to High(StaticArray) do
2013-04-10 16:57:12 -07:00
begin
2018-06-22 20:57:24 +00:00
DynamicArray[ixD] := StaticArray[ixS];
Dec(ixD);
end;
// Concatenating the static and dynamic array into a single string variable
StaticArrayText := '';
for ixS := Low(StaticArray) to High(StaticArray) do
StaticArrayText := StaticArrayText + IntToStr(StaticArray[ixS]);
DynamicArrayText := '';
for ixD := Low(DynamicArray) to High(DynamicArray) do
DynamicArrayText := DynamicArrayText + IntToStr(DynamicArray[ixD]);
2013-04-10 16:57:12 -07:00
end;
// Displaying both arrays (#13#10 = Carriage Return/Line Feed)
ShowMessage(StaticArrayText + #13#10 + DynamicArrayText);
end;