Forum > Beginners

Single deminision arrays(Solved)

<< < (2/4) > >>

JLWest:
I don't understand. You defined the array as a Const.

Do they have to be a Const?

I'll try it.

Const Deck : Array[1..52] of Integer;
Const South : Array[1..13] of integer;
Const North : Array[1..13] of integer;
Const East   : Array[1..13] of integer;
Const West  : Array[1..13] of integer;

JLWest:
That didn't work. Got an error 'unit1.pas(334,38) Fatal: Syntax error, "=" expected' but ";" found on Const Deck : Array[1..52] of Integer;  It looks like it looking for values in the array elements.

Deck : Array[1..52] of CardRecords;
South : Array[1..13] of integer;
North : Array[1..13] of integer;
East   : Array[1..13] of integer;
West  : Array[1..13] of integer;

The Deck array holds a record with card attributes, suit, position ect.
The North, South,East and West represent the hands at a bridge table. The integers
in the hand arrays could be an integer value of 1..52 and would be a card of the Deck.

I need to change the values in al 5 arrays while playing a hand of bridge.

Is there a way to have a static array that is 1 based as opposed to 0 based?

wp:
You declare a static array like any other variable and specify the index limits in the declaration; in this case you must enter the values one by one:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var  South: array[1..3] of Integer;begin  South := 10;  South := 32;  South := 41;
You can also initialize the array element immediately in the declaration by calling

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var  South:array[1..3] of Integer = (10, 32, 41);// orconst  South: array[1..3] of Integer = (10, 32, 41);Although in the second case, the array is declared as "const", it still can be changed in the default settings of FPC/Lazarus. A pecularity of the Pascal language. Read about "typed constants" in https://www.freepascal.org/docs-html/ref/refse10.html.

jamie:

--- Quote from: JLWest on June 18, 2022, 11:30:53 pm ---That didn't work. Got an error 'unit1.pas(334,38) Fatal: Syntax error, "=" expected' but ";" found on Const Deck : Array[1..52] of Integer;  It looks like it looking for values in the array elements.

Deck : Array[1..52] of CardRecords;
South : Array[1..13] of integer;
North : Array[1..13] of integer;
East   : Array[1..13] of integer;
West  : Array[1..13] of integer;

The Deck array holds a record with card attributes, suit, position ect.
The North, South,East and West represent the hands at a bridge table. The integers
in the hand arrays could be an integer value of 1..52 and would be a card of the Deck.

I need to change the values in al 5 arrays while playing a hand of bridge.

Is there a way to have a static array that is 1 based as opposed to 0 based?

--- End quote ---

what you are looking for is a fixed. Dynamic arrays are 0 based. just use a fixed array somewhere.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Var South :Array[1..13] of integer; ....
If you are having problems passing that to functions then create a type.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- Type  TMyCompasArray = Array[1..13] of integer;  // when you define it some where. Var South : TMyCompasArray;
When passing these to functions create the function to accept this type as a Reference so you make changes to it.
For example
Function AcceptMyCompasArrays(Var aCompasArray:TMyCompasArray);.....

if you stick with using this type you can pass a reference to the array of any procedure or function.

Hoped that gave you a little more insight.

JLWest:
Yea, That did it. Declaring as a type.

Thanks all.