Access to the private fields and public properties of the class lazarus / 62-General ---------------------------------------------------------------------- woodhead · 2021-07-16 12:37 Hello. I faced the following situation: the same code is compiled in Lazarus 2.0.8 and is not compiled in Lazarus 2.0.12. 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   TColor = (red, green, blue);   TShape = class  private    fColor: TColor;  public    property Color: TColor read fColor write fColor;  end;   TShapeWrapper = class  private    fShape: TShape;  public    property Color: TColor read fShape.fColor write fShape.fColor; // there is an error in this line  end;In Lazarus 2.0.12, error messages appear when trying to compile this code: QuoteCompile Project, Target: project1.exe: Exit code 1, Errors: 2 unit1.pas(31,39) Error: Record or object type expected unit1.pas(31,59) Error: Record or object type expectedLine 31 looks 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 property Color: TColor read fShape.fColor write fShape.fColor;All the code is located within a same module. Please tell me how to fix it? ---------------------------------------------------------------------- lucamar · 2021-07-16 12:45 I don't know whether it will work but, have you tried with: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 property Color: TColor read fShape.Color write fShape.Color;so as to not access a private field? If that doesn't work you'll have to use a getter/setter, I think. ---------------------------------------------------------------------- woodhead · 2021-07-16 12:50 For this line: 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 property Color: TColor read fShape.Color write fShape.Color;get errors: QuoteCompile Project, Target: project1.exe: Exit code 1, Errors: 4 unit1.pas(31,39) Error: Record or object type expected unit1.pas(31,40) Error: Unknown record field identifier "Color" unit1.pas(31,58) Error: Record or object type expected unit1.pas(31,59) Error: Unknown record field identifier "Color"I would not like to use getters/setters. ---------------------------------------------------------------------- howardpc · 2021-07-16 13:15 Quote from: woodhead on July 16, 2021, 02:50:04 pmI would not like to use getters/setters. Like it or not, if you want to use properties you have to respect the syntax. The FPC loophole by which you could read/write property values by direct access to the underlying field was closed some time ago. ---------------------------------------------------------------------- woodhead · 2021-07-16 13:27 Yep, https://wiki.lazarus.freepascal.org/User_Changes_Trunk#Property_f ield_access_lists_no_longer_allows_classes Thanks ---------------------------------------------------------------------- lucamar · 2021-07-16 14:33 Quote from: woodhead on July 16, 2021, 03:27:24 pmYep, https://wiki.la zarus.freepascal.org/User_Changes_Trunk#Property_field_access_lists_no _longer_allows_classes Thanks But that is for trunk; if you're using a normal 2.0.12 release you've got FPC 3.2.0, which shouldn't have that change ... at least it isn't mentioned in User Changes 3.2.0 ---------------------------------------------------------------------- MarkMLl · 2021-07-16 15:03 Out of curiosity: it used to be possible with Delphi to "surface" items by subclassing... does that work with FPC? In any event, fudging something like that would probably be more work than doing it properly using properties. MarkMLl ---------------------------------------------------------------------- Kays · 2021-07-16 15:18 Do you really need a “wrapper”? Doesn’t inheritanceCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TShapeWrapper = class(TShape) … end;do the same job? ---------------------------------------------------------------------- woodhead · 2021-07-17 02:30 Quote from: lucamar on July 16, 2021, 04:33:31 pmBut that is for trunk; if you're using a normal 2.0.12 release you've got FPC 3.2.0, which shouldn't have that change ... at least it isn't mentioned in User Changes 3.2.0 You are right. I thought so too. Quote from: Kays on July 16, 2021, 05:18:21 pmDo you really need a “wrapper”? Doesn’t inheritanceCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TShapeWrapper = class(TShape) … end;do the same job? This is a synthetic example to demonstrate the problem. I don't want to pile up inheritance where it can be made easier. ---------------------------------------------------------------------- PascalDragon · 2021-07-17 14:21 Quote from: lucamar on July 16, 2021, 04:33:31 pmQuote from: woodhead on July 16, 2021, 03:27:24 pmYep, https://wiki.lazarus.freepascal.org/ User_Changes_Trunk#Property_field_access_lists_no_longer_allows_classe s Thanks But that is for trunk; if you're using a normal 2.0.12 release you've got FPC 3.2.0, which shouldn't have that change ... at least it isn't mentioned in User Changes 3.2.0 Seems like it was missed to move that entry to User Changes 3.2.0, I've done so now. Quote from: woodhead on July 16, 2021, 02:50:04 pmI would not like to use getters/setters. Simply do use getters and setters and declare them as inline. ---------------------------------------------------------------------- lucamar · 2021-07-17 16:37 Quote from: PascalDragon on July 17, 2021, 04:21:17 pmSeems like it was missed to move that entry to User Changes 3.2.0, I've done so now. Thanks, Dragon. It was a little baffling to have the info as if it were for trunk but the behaviour sneaking up in the release