Forum > Pas2JS

Cannot nest anonymous array

(1/1)

SudoKai:
Just started playing around with pas2js and got stuck with Multi-Dimensional Arrays. I get 'Error: Cannot nest anonymous array' with the following:


--- 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 Multi_Array: Array of Array of Array of Integer;
I can bypass with the following code:


--- 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 Multi_Array_Level_02 = record  M_Array_Level_02: Array of Integer; end; Type Multi_Array_Level_01 = record  M_Array_Level_01: Array of Multi_Array_Level_02; end; Var Multi_Array: Array of Multi_Array_Level_01;
I also skimmed through the 'Pas2JS-WebGL demo' to see if there was a piece of code using Multi-Dimensional Arrays. But I spotted this comment in 'Mat4.pas'


--- 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";}};} ---// NOTE: [][] doesn't typecast to array of syntax so we need this
So is Multi-Dimensional Arrays not supported in pas2js just yet, or is it my programming skills that needs some adjustment?

Thaddy:
It should work. Try the most recent version and if that does not work file a bug report on Mantis.

--- 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";}};} ---program ma;Var Multi_Array: Array of Array of Array of Integer;beginend.

PascalDragon:
Nested anonymous array are currently not supported in Pas2JS as the compiler remarks (Error: Cannot nest anonymous array). You need to declare each sub array:


--- 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";}};} ---program tdynarr; type  TLongIntArray = array of LongInt;  TLongIntArrayArray = array of TLongIntArray;  TLongIntArrayArrayArray = array of TLongIntArrayArray;  TLongIntArrayArrayArrayArray = array of TLongIntArrayArrayArray; var  arr: TLongIntArrayArrayArrayArray;// array of array of array of array of LongInt; beginend.

Thaddy:
Yes that works, but it reads like a train station in Wales....
( which to be fair is actually https://en.wikipedia.org/wiki/Rhoose_Cardiff_International_Airport_railway_station )

Navigation

[0] Message Index

Go to full version