Using the record type inside a self-declaration lazarus / 64-FPC development ---------------------------------------------------------------------- ASerge · 2024-07-02 21:13 I didn't even know it was possible. From which version? 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  TRec = record    FRecs: array of TRec;    FOther: Integer;  end; ---------------------------------------------------------------------- VisualLab · 2024-07-02 21:24 I checked too. Works. The magic of pointers. ---------------------------------------------------------------------- Thaddy · 2024-07-03 09:20 As far as I know this was syntactically always possible, but I wonder why since it is technically recursive so can explode on use. Especially if you use that on a record itself instead of pointer to record. It keeps allocating memory in an infinite way. Although here it uses a dynamic array of self and that is indeed a pointer. If it were a static array, it explodes. ---------------------------------------------------------------------- MarkMLl · 2024-07-03 09:27 But FRecs there is a dynamic array, so all that's being allocated is a reference to the actual array storage on the heap. MarkMLl ---------------------------------------------------------------------- ASerge · 2024-07-03 12:39 Quote from: Thaddy on July 03, 2024, 11:20:37 amAs far as I know this was syntactically always possible In early versions of Delphi, where there were already dynamic arrays, this is explicitly a compilation error. I haven't checked in the latest versions. ---------------------------------------------------------------------- Thaddy · 2024-07-03 13:01 Yes, same as FPC will throw an error. (Except D2, I believe, that simply crashes, can you test that 440bx?    it is from memory and I need to install D2 from diskettes ) e.g.: 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  TRec = record    FRecs: array[0..3] of TRec;// this will cause an infinite amount of Trec allocations    FOther: Integer;  end; is recursion and forbidden for the obvious reason. Hence the dynamic array works, because it is a pointer type and managed. ---------------------------------------------------------------------- 440bx · 2024-07-03 16:19 Delphi 2 does not accept either definition. The definition @Serge posted causes an "[ expected but 'OF' found" and the definition @Thaddy posted causes "Type 'TRec' is not yet completely defined' (which makes sense, that should never compile.) Delphi 2 won't even accept 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  T = array of TREC;  It looks like in Delphi 2, "array of something" is only allowed in parameter types not type definitions. ---------------------------------------------------------------------- Thaddy · 2024-07-03 18:11 Delphi 2 was before dynamic arrays. my question is if it crashes with the static array? I have delphi 2, but need a reader for my disks.... Which I have, but my attick is even less organized than my brains...( some might say properly organized) ---------------------------------------------------------------------- 440bx · 2024-07-03 18:18 Quote from: Thaddy on July 03, 2024, 08:11:24 pmDelphi 2 was before dynamic arrays. my question is if it crashes with the static array? I am not understanding what you are asking me to test.  Please provide a code snippet of what you'd like me to test. ---------------------------------------------------------------------- Thaddy · 2024-07-03 19:19 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  TRec = record    FRecs: array[0..3] of TRec;// this will cause an infinite amount of Trec allocations    FOther: Integer;  end;that one. if you assign it to a variable. note this is a static array, not dynamic. be careful, it leads to an out of memory error.. so plz be safe! ---------------------------------------------------------------------- 440bx · 2024-07-03 20:07 Quote from: Thaddy on July 03, 2024, 09:19:34 pmCode: 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  TRec = record    FRecs: array[0..3] of TRec;// this will cause an infinite amount of Trec allocations    FOther: Integer;  end;that one. if you assign it to a variable. note this is a static array, not dynamic. be careful, it leads to an out of memory error.. so plz be safe! I tested that already and gave the result in the previous post.  The result is an error message from Delphi 2: "Type 'TRec' is not yet completely defined' Which is the correct error message since the statement is semantically incorrect (it references itself.) ---------------------------------------------------------------------- ASerge · 2024-07-04 01:50 Quote from: Thaddy on July 03, 2024, 03:01:45 pmHence the dynamic array works, because it is a pointer type and managed. Thaddy, please check (the initial code) on the latest version of Delphi. ---------------------------------------------------------------------- Thaddy · 2024-07-04 08:46 I already checked that. Because the array is dynamic it works. Now change it to static and the compiler duely explains that Trec is not fully defined. Older Delphi's (D4) explode, D7 is the first I have that doesn't. I have most still installed as commandline compilers:3,4,2006,2007,2009, XE2. 3 didn't have dynamic arrays yet. I also have D2 and therefor also D1, and the kylixes,but they are not installed anywhere. Note D4 on my machine has a little quirk, it uses the rtl and vcl from D5.. Don't worry, everything legal, I have licenses for all. Side note: I also have a fpc2.6 with the Delphi5 rtl and vcl except for the system unit. Note that the rtl and vcl are compiled with the gpl flag set, which is required. See the Kylix docs. ---------------------------------------------------------------------- MarkMLl · 2024-07-04 08:55 Quote from: Thaddy on July 04, 2024, 10:46:57 amI already checked that. Because the array is dynamic it works. Now change it to static and the compiler duely explains that Trec is not fully defined. Older Delphi's (D4) explode, D7 is the first I have that doesn't. Explosion is unambiguously wrong. However I think we have to take into account that even though declaring a dynamic array as a record field (in the same way that a non-short string may be declared) makes sense, at least some versions of the compilers might erroneously reject it as an error: even if able to generate correct code. MarkMLl ---------------------------------------------------------------------- Thaddy · 2024-07-04 09:02 The only one that I have and explodes is Delphi4. At least from D7 onwards the compilers throw errors, as does fpc. So it is basically a non-issue. ---------------------------------------------------------------------- 440bx · 2024-07-04 09:04 Quote from: Thaddy on July 04, 2024, 11:02:26 amAt least from D7 onwards the compilers throw errors, as does fpc. Delphi 2 throws an error as well. ---------------------------------------------------------------------- Thaddy · 2024-07-04 16:18 Thanks for testing. ---------------------------------------------------------------------- 440bx · 2024-07-04 19:23 Quote from: Thaddy on July 04, 2024, 06:18:09 pmThanks for testing. You're welcome. ---------------------------------------------------------------------- PascalDragon · 2024-07-04 19:36 Quote from: ASerge on July 02, 2024, 11:13:18 pmI didn't even know it was possible. From which version? 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  TRec = record    FRecs: array of TRec;    FOther: Integer;  end; That works because it is essentially the same as 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  PRec = ^TRec;  TRec = record    FRecs: PRec;    FOther: Integer;  end;