Forum > Beginners

Initializing arrays

(1/1)

JMarques:
Hello, is there some way to initialize directly an array as below? I get an error in FreePascal. Tried the {$MODE OBJFPC} but to no avail. Thanks!!


--- 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  Perm: array[1..3] of Integer;  i: Integer;begin  case n of  0: Perm := [1, 2, 3];  1: Perm := [1, 3, 2];  2: Perm := [3, 2, 1];  3: Perm := [2, 1, 3];  4: Perm := [2, 3, 1];  5: Perm := [3, 1, 2];  end;  

dseligo:
You have to use FPC trunk for that.
In FPC 3.2.2 that kind of initialization still doesn't work.

simone:
In the case of dynamic arrays, as in the following code, this type of initialization is possible with fpc 3.2.2.


--- 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";}};} ---{$mode ObjFpc}var  Perm: array of Integer;  i: Integer;  n : integer;begin  case n of  0: Perm := [1, 2, 3];  1: Perm := [1, 3, 2];  2: Perm := [3, 2, 1];  3: Perm := [2, 1, 3];  4: Perm := [2, 3, 1];  5: Perm := [3, 1, 2];  end;end.  

jamie:
I think he looking for a multi dem arary..


--- 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";}};} ---VarTheItem :Array [1..6, 1..3] of integer = ((1,2,3),(4,5,6).......................); 

JMarques:

--- Quote from: simone on April 13, 2023, 12:58:29 am ---In the case of dynamic arrays, as in the following code, this type of initialization is possible with fpc 3.2.2.


--- 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";}};} ---{$mode ObjFpc}var  Perm: array of Integer;(...)end.  
--- End quote ---

Thank you, it worked!

Navigation

[0] Message Index

Go to full version