Forum > General

Advanced records public and private differences

(1/1)

440bx:
Hello,

I was reading the documentation to get a better idea of the difference between a field in an advanced record's public section and one in a private section.

The only difference I found is that fields accessed by record helper(s) for those records must be in the public section.

Is that the _only_ accessibility difference between public and private or are there other cases (not just being used in record helpers) where the private/public visibility makes a difference ?... if there is, I would much appreciate an example.

Thank you for your help.

dseligo:
Fields and methods declared in private section can't be used outside of unit where advanced record is declared.
And fields and methods declared in strict private section can't be used only inside of methods of advanced record.

440bx:

--- Quote from: dseligo on May 15, 2024, 10:21:24 am ---Fields and methods declared in private section can't be used outside of unit where advanced record is declared.

--- End quote ---
IOW and, if I understood you correctly, fields in the private section are only visible in the unit in which the record is declared.  (similar to declaring a variable in the implementation section of a unit, it will only be visible in the unit and not outside of it.)

If you can confirm my understanding is correct (or not if it isn't), I would appreciate that.  Thank you.

dseligo:
Exactly.


--- 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 project1; {$mode ObjFPC}{$H+} uses unit1; var a: TTestAdvRec; begin  a.Prop1 := 10;  WriteLn(a.Func2);  //WriteLn(a.Func1); // can't be accessed  //a.Field1 := 10; // can't be accessed  //a.Field2 := 10; // can't be accessedend.

--- 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";}};} ---unit Unit1; {$mode ObjFPC}{$H+}{$modeswitch ADVANCEDRECORDS} interface type  TTestAdvRec = record  private    Field1: Integer;    function Func1: integer;  strict private    Field2: Integer;  public    property Prop1: Integer read Field1 write Field1;    function Func2: integer;  end; function SomeFunction: Integer; implementation function TTestAdvRec.Func1: integer;begin  Result := 22;end; function TTestAdvRec.Func2: integer;begin  Field2 := 2;  Result := 22;end; function SomeFunction: Integer;var a: TTestAdvRec;begin  a.Field1 := 10;  //a.Field2 := 10; // strict private - can't be accessed here  Result := 22;end; end.

440bx:
Thank you dseligo.  That was very helpful. :)

Navigation

[0] Message Index

Go to full version