Forum > General

Effect of adding properties before the visibility sections?

(1/3) > >>

vfclists:
I recently got to learn that placing a property before any of the visibility sections in a class definition made it a published property automatically, and it tested out OK.


--- 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";}};} ---  TMyComponent = class(TComponent)    FSomeUnPublishedValue: integer;    property AnInteger: integer read FAnInteger write SetAnInteger;    property WideStr: widestring read FWideStr write FWideStr;    property Grid: TDBGrid read FDataGrid write FDataGrid;    property Panel: TPanel read FPanel write FPanel;  private    FAnInteger: integer;    FWideStr: widestring;    FUnicodeStr: unicodestring;    FAnsiStr: ansistring;    FDataGrid: TDBGrid;    FPanel: TPanel;    FEdit: TEdit;    FControl: TComponent;    procedure SetAnInteger(const AValue: integer);  public  published    property UnicodeStr: unicodestring read FUnicodeStr write FUnicodeStr;    property AnsiStr: ansistring read FAnsiStr write FAnsiStr;    property Edit: TEdit read FEdit write FEdit;    property AControl: TComponent read FControl write FControl;  end;

This leads me to two questions.

1. Does this mean all values before the visibility fields are accessible to FreePascal in other units as are all public and published fields, but only published properties and the properties before the visibility sections will be available to RTTI, ie obtainable from using the methods in TypInfo?

2. When the compile lays out the memory arrangement of the fields, will the properties before the visibility sections be treated as though they were declared in the published sections?

TRon:

--- Quote from: vfclists on October 20, 2024, 01:57:39 pm ---I recently got to learn that placing a property before any of the visibility sections in a class definition made it a published property automatically, and it tested out OK.

--- End quote ---

No visibility specifier declared means section public see reference manual:

--- Quote ---For objects, three visibility specifiers exist: private, protected and public. If a visibility specifier is not specified, public is assumed.

--- End quote ---

icw published in class definition here:

--- Quote ---From a language perspective, this is the same as a Public section, but the compiler generates also type information that is needed for automatic streaming of these classes if the compiler is in the {$M+} state. Fields defined in a published section must be of class type. Array properties cannot be in a published section.

--- End quote ---

That should be able to answer at least some of your questions.

MarkMLl:
While not specifically addressing your questions, I'd add that two or three months ago I was looking at something related in the case of class variables ("fields") and found I had to do something like 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";}};} ---  TBlip= class    class var InfieldDegs: TVertexDegs; (* Used for range calculation           *)    class var RadioDegs: TVertexDegs;   (* Used for slant calculation           *)    class var RadioAlt: integer;        (* Used for slant calculation           *)  public                                (* This is needed to close var section  *)    Timestamp: TDateTime;    ReceiveTime: Double;... 
So in effect that confirms that lines before a visibility specifier are public, but it turned out to be necessary to have an explicit "public"  before ordinary fields could be defined.

https://forum.lazarus.freepascal.org/index.php/topic,67667.msg521441.html#msg521441

MarkMLl

cdbc:
Hi
IIRC by convention the fields and methods in the section between 'class' & visibility specifiers are 'published'.
And AFAICT it's this feature, e.g.: Castle GE exploits in its framework wrt. auto-creation of objects... I think via streaming...?!?
It would naturally depend on {$M+}
Regards Benny

TRon:

--- Quote from: cdbc on October 20, 2024, 03:51:09 pm ---IIRC by convention the fields and methods in the section between 'class' & visibility specifiers are 'published'.

--- End quote ---
According to the reference manual they are public therefor they are public  :)

Navigation

[0] Message Index

[#] Next page

Go to full version