Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does ParentBackground work on IDE generated Forms?

Tags:

delphi

tform

This code works fine with an IDE generated form in a VCL Forms Application:

Self.ParentBackground := True;


But why? None of the ascendants (TForm, TCustomForm, TScrollingWinControl) publish the protected ParentBackground property of TWinControl. The type declaration for the form (f.i. 'TForm1') at the top of the unit, does not either. Indeed, as expected, this

TForm(Self).ParentBackground := True;

does not compile ("Cannot access protected symbol TWinControl.ParentBackground"). Same with any form created at runtime.


Note: The question is not about how can I set the property (BTW, there are others, like 'Bevel[xxx]'), I'd like to know how does this work.

like image 642
Sertac Akyuz Avatar asked Dec 21 '22 17:12

Sertac Akyuz


2 Answers

Self.ParentBackground := True;

compiles because a class can access its own protected members.

like image 188
David Heffernan Avatar answered Dec 24 '22 01:12

David Heffernan


But TForm1(Self).ParentBackground works. The difference is that the class TForm1 (which Self belongs to) is declared in the same unit; then you can indeed access protected members.

like image 35
Andreas Rejbrand Avatar answered Dec 24 '22 02:12

Andreas Rejbrand