Polymorphism (as provided by Pascal classes) doesn't mix well with assignment operator overloading in this case.
When targeting the
Parent property, the required operator would have to be
operator :=(ASelf: TLabeledPanel): TWinControl; which is an
impossible overload because it's an
upcast. The necessity of invoking such an upcast operator is impossible to determine since in principle, subclasses
already act equivalently to some superclass when invoking one of the latter's (non-virtual) methods.
For example:
ControlAtPos() is defined on
TWinControl. When invoking it on a
TLabeledPanel instance, should the compiler first call the custom assignment operator (which may in principle have all kinds of side effects, such as rearranging child controls) or should it call the method directly? With virtual methods, how should the compiler know whether to invoke the overridden or the inherited one?
Apart from that, the existing code in the LCL has no way of knowing whether such a user-defined overload exists at all, making it impossible to be applied consistently.
TObject (+ IFPObserved)
┗━━ TPersistent (+ IUnknown, IInterfaceComponentReference)
┗━━ TComponent
┗━━ TLCLComponent
┗━━ TControl
┗━━ TWinControl
┗━━ TCustomControl
┗━━ TCustomPanel
┗━━ TPanel
┗━━ TLabeledPanel
Assert(Panel is TLabeledPanel); // True
Assert(Panel is TPanel); // True
Assert(Panel is TCustomPanel); // True
Assert(Panel is TCustomControl); // True
Assert(Panel is TWinControl); // True
{...}
In my opinion, defining an opaque and somewhat confusing operator overload just to save 10 keystrokes isn't worth it. I encourage you to just make
FFlowPanel publicly accessible - this is probably the simplest solution:
TLabeledPanel = class(TPanel)
FLabel: TLabel;
FFlowPanel: TFlowPanel;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
property FlowPanel: TFlowPanel read FFlowPanel;
end;