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:
csDestroying
in its state.FreeNotifiers
part. I can't understand.components
list and:
components
listWhen 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?
What the FreeNotification
mechanism does is notifies registered components that this component is being freed. They then use their Notification
method to ensure that they don't hold any references to it (which is what your example is doing) so that they don't end up with dangling references to an invalid object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With