Forum > General
Initializing Record with Array Content
local-vision:
So I am able to initialize the variable S1 record with the array AOS with a set of Strings.
But if want to do the same with an array that I declared before that, it fails.
Any ideas?
--- 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 Tar=record AOS: array of string; end; const List1: array[0..2] of String = ('First','Second','Third'); List2: array of String = ('First','Second','Third'); S1:Tar=(AOS:('First','Second','Third')); // Works S2:Tar=(AOS:List1); // Error: Syntax error, "(" expected but "identifier LIST1" found S3:Tar=(AOS:List2); // Error: Syntax error, "(" expected but "identifier LIST2" found
korba812:
This limitation is probably due to the fact that typed constants are like variables.
https://www.freepascal.org/docs-html/ref/refse10.html
I don't know if or how to get around it. You probably have to live with it ;).
local-vision:
What about this:
--- 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 Tar=record AOS: array of string; end; const List1: array[0..2] of String = ('First','Second','Third'); List2: array of String = ('First','Second','Third'); var S1:Tar=(AOS:('First','Second','Third')); // Works S2:Tar=(AOS:List1); // Error: Syntax error, "(" expected but "identifier LIST1" found S3:Tar=(AOS:List2); // Error: Syntax error, "(" expected but "identifier LIST2" found
I get the same situation
korba812:
Analogous to what I wrote earlier: initialized variables are similar to typed constants, the difference is when initialization occurs.
https://www.freepascal.org/docs-html/ref/refse24.html#x55-750004.4
And you can't use variable to initialize a constant (edit: maybe with exceptions, like a pointer to a variable...).
local-vision:
Appreciated the prompt reply and info. Reviewing.
--- Quote from: korba812 on July 23, 2024, 09:36:11 pm ---And you can't use variable to initialize a constant (edit: maybe with exceptions, like a pointer to a variable...).
--- End quote ---
It seems that what I am attempting to achieve is not really possible.
Navigation
[0] Message Index
[#] Next page