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?
No,
any property in a
published-section (be it the implicit default section or an explicit one) will be available through RTTI. It's just how Delphi does things and Lazarus followed suit. It could just as well declare a separate
published-section.
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?
The order of fields is an implementation detail and with optimization
-O4 this order might even change if the compiler can make the class definition smaller.
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.
No visibility specifier declared means section public see reference manual:
For objects, three visibility specifiers exist: private, protected and public. If a visibility specifier is not specified, public is assumed.
The documentation is not
entirely accurate here. The default visibility section of a
class is
public, however if the class is compiled with
$M+ or descends from one that has that enabled it then the default section is instead
published.
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
Does a field need to be declared as property and be in the published section area or before the visibilty specifiers before it can streamed, in short can a field be streamed without being labelled as a property?
Only if the field is a class that has
$M enabled or descends from one that has (e.g.
TPersistent).