[fpc-pascal] What is the difference between the declarations at the beginning of a class and those declared in the public section?

Sven Barth pascaldragon at googlemail.com
Sun Nov 6 21:42:11 CET 2011


On 06.11.2011 21:28, Frank Church wrote:
> If that is the case then a lot of Free Pascal and Delphi demos are
> teaching bad practices because they make most members accessible
> externally when there is no real reason to. I never thought about that
> much because I just wanted to get my apps working rather than think
> about proper OOP practices, especially in the case of UI objects like
> forms, controls etc

If you talk about the fields that are for the controls in a form, than 
this is intended. TForm, TFrame and TDataModule are descendants of 
TPersistent which has the {$M} option enabled, thus the default 
visibility is "published" and then and only then these fields and 
methods are accessible through RTTI (*). This is e.g. needed if you want 
to use a file like a DFM/LFM which stores your layout information (the 
way the GUI in Delphi/Lazarus works).

(*) The extended RTTI of Delphi 2009 and newer allows more options 
regarding this.

Regards,
Sven



More information about the fpc-pascal mailing list