1
votes

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?

1
An application of self-discipline usually does the job.David Heffernan
If self-discipline was all it takes ... than there would be no need for private, protected and public properties, would there? .........Bascy
Visibility levels do more though. They also provide documentation of what the interface is. As for your question I can't really picture your current code.David Heffernan
How does the C# sealed analogues in your situation? A sealed class cannot be used as a base class.kobik
Maybe "protect" the published setters by testing the Self class and making sure only the base class can use the setter property.kobik

1 Answers

1
votes

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.