Currently, I am trying to understand Delphi's VCL, specifically, the notification mechanism (which is a great mechanism in my point of view).
When I was studying on this subject, I remembered of the TLabeledEdit
, of course I have been using it for long time, but I never had chance to stop and study it's code.
As I understand so far:
When a TComponent is destroyed:
- It will notify all its children's components, to include
csDestroying
in its state. FreeNotifiers
part. I can't understand.- Will iterate the
components
list and:- Remove each item from the
components
list - Actually destroy each component instance.
- Remove each item from the
When a child component is being destroyed, it restarts the same process for all of its children components. So, as far as I can tell, this is a chain effect.
What I can't understand is the FreeNotification
, what could I possibly do with it?
Let's think about the TLabeledEdit
in first place. The relevant part of the notification, in TLabeledEdit
's code is an override on the Notification
function, with the following code:
if (AComponent = FEditLabel) and (Operation = opRemove) then
FEditLabel := nil;
What could have happened if FreeNotification
was not used?
In General, what benefits would I have because of this mechanism and what am I not seeing that might eventually make its existence necessary?