[SOLVED]Const Array of Const Records, all fields have to be filled individually? lazarus / 61-Beginners ---------------------------------------------------------------------- BrainChemistry · 2018-08-12 14:38 Hi there, I'm aware this works, and there are thousands of examples like this on the internet: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TPoint = record     X, Y: Single;  end; const  Points: array[0..2] of TPoint = ((X: 0.0; Y: 0.0),  (X: 1.0; Y: 1.0),  (X: 2.0; Y: 2.0))  Though what I can't get running is something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TPoint = record     X, Y: Single;  end; const  Point1: TPoint = (X: 0.0; Y: 0.0);  Point2: TPoint = (X: 1.0; Y: 1.0);  Point3: TPoint = (X: 2.0; Y: 2.0);   Points: array[0..2] of TPoint = (Point1, Point2, Point3);  Also trying to have Points not being a const but a var. didn't work unless I specify all the fields individually (as seen in first code example): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TPoint = record     X, Y: Single;  end; const  Point1: TPoint = (X: 0.0; Y: 0.0);  Point2: TPoint = (X: 1.0; Y: 1.0);  Point3: TPoint = (X: 2.0; Y: 2.0); var  Points: array[0..2] of TPoint = (Point1, Point2, Point3);  Since I couldn't find any example on the internet, I guess it's not possible, or what am I missing here? Thanks in advance. ---------------------------------------------------------------------- 440bx · 2018-08-12 15:03 Hi, The compiler is doing the right thing and the reason what you want and, are trying to do doesn't work is a bit subtle but not much. The declaration: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Points: array[0..2] of TPoint = (Point1, Point2, Point3);is invalid because the only way to make it valid is to _copy_ Point1, Point2 and Point3 into the Points array.  The compiler won't do that for you. What you're trying to do can be done if you change the declarations a bit.  The following example works and does what you are trying to do (albeit in a different way than the one you attempted): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program InitializedStucturedConstants; type  PPoint = ^TPoint;  TPoint = record    X, Y: Single;  end; const  Point1: TPoint = (X: 0.0; Y: 0.0);  Point2: TPoint = (X: 1.0; Y: 1.0);  Point3: TPoint = (X: 2.0; Y: 2.0); //Points: array[0..2] of TPoint = (Point1, Point2, Point3); Points   : array[0..2] of PPoint = (@Point1, @Point2, @Point3); begin  with Points[1]^ do writeln('X : ', X, '  Y : ', Y);end.  To reference the points you've declared, you need to use pointers to them. You cannot use the points themselves because then the const Point1 and the array element Point1 are two _distinct_ items in memory, not the same one which is probably what you want it to be. HTH. ---------------------------------------------------------------------- BrainChemistry · 2018-08-12 15:52 That's brilliant, thanks. ---------------------------------------------------------------------- PascalDragon · 2018-08-14 11:42 Quote from: BrainChemistry on August 12, 2018, 04:38:09 pmSince I couldn't find any example on the internet, I guess it's not possible, or what am I missing here? 440bx already provided you with a solution, nevertheless as an explanation: your Point1, etc. declarations are so called typed constants (they have a : typename). However to use them inside another constant declaration you need to use untyped constants (without : typename, though this isn't supported for structured types). ---------------------------------------------------------------------- marcov · 2018-08-14 11:50 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Or     type      TPoint = record         X, Y: Single;      end;         const      Points: array[0..2] of TPoint = ((X: 0.0; Y: 0.0),  (X: 1.0; Y: 1.0),  (X: 2.0; Y: 2.0));         var         Point1: TPoint absolute points[0];        Point2: TPoint absolute points[1];        Point3: TPoint absolute points[2]; begin  writeln(point2.x,' ',point3.x);end. Though this might not work on targets where typed constants are not in the datasegment (?). ---------------------------------------------------------------------- 440bx · 2018-08-14 14:02 Quote from: marcov on August 14, 2018, 01:50:44 pmThough this might not work on targets where typed constants are not in the datasegment (?). I'm only familiar with how the compiler works under Windows.  Given that these "constants" really aren't constants, just initialized variables, are there targets where they are not in a writeable data segment ? ---------------------------------------------------------------------- marcov · 2018-08-14 14:12 Quote from: 440bx on August 14, 2018, 04:02:42 pmQuote from: marcov on August 14, 2018, 01:50:44 pmThough this might not work on targets where typed constants are not in the datasegment (?). I'm only familiar with how the compiler works under Windows.  Given that these "constants" really aren't constants, just initialized variables, are there targets where they are not in a writeable data segment ? microcontrollers often have a lot more flash than memory.