I have defined a base VCL form class with a (non-visual) designtime component on it that contains a collection of styles.
I want to prevent developers (and myself) to change those styles in the forms that are derived from my base form. To speak in C# terms, I would like the component to be sealed in the base VCL form.
How can I achieve that?
On a side note: I never did understand the declaration of designtime components on a form in Delphi.. kinda public but not placed in the public section of the class declaration. Can anybody explain the reason for this?
Well, short answer you can't. In case you really need it I would suggest to create the component in run-time and make it private. If you are using GExpert (click here) you may use "Components to Code" command to get the required code. If you need more details, please share your DFM file and I will post the corresponding code here.
As for your side note, the components are declared as published. See Visibility of Class Members quote
If a member's declaration appears without its own visibility specifier, the member has the same visibility as the one that precedes it. Members at the beginning of a class declaration that do not have a specified visibility are by default published, provided the class is compiled in the {$M+} state or is derived from a class compiled in the {$M+} state; otherwise, such members are public
NB TForm
is a descendant of TPersistent
which is compiled with {$M+}
directive
PS the published declaration is required for TComponent.SetName
(actually TComponent.SetReference
) which should assign the component reference to the corresponding field when you modifying the component Name
property.