From RAD Studio API Documentation
Jump to: navigation, search

Linked components

TComponent.Notification does not work over a single owner?!! Why??? My case: I have two my components (say, A and B) on a form, and component A have a component-typed property that can links to component B. This property need some initialization and finalization, ie I must in A implementation do something with this B just after it linked and just before it unlinked. Even if this B are unlinking while destroying of both! I'm expect in first time that I have notification mechanism, and A will be notified before B try to be destroyed. But in case A and B stay on single owner, I have not this notification at all! I have destroyed B, then destroying A, and this A have link to destroyed И and trying to finalize it! Some times it is EAccessViolation, some times a silent chaos! What I need to do??? --Nashev 01:55, 19 September 2012 (PDT)

UPD: When TComponent.Destroy working, it firstly call notification for all FFreeNotifies for other's owned components, and after that, if it still have Owner (what reasons can be to not have owner in this stage?), it call Owner.RemoveComponent where this Owner call self Notification about this. In this self TComponent.Notification, they can call Notification for all owned components and through this way notification may come to all owned components, when one of they child are destroyed. BUT - it do nothing, because before call to this notification, Destroy go to DestroyComponents! It removes all owned components before that. It can call Free for all owned components without call Notification or with it, if that already have flag csFreeNotification (this flag can be set only if FreeNotification was called for this component for any) or if it are inline in design size. It really does not use FreeNotification lists, but works only if FreeNotification was called. --Nashev 02:00, 20 September 2012 (PDT)

Thank you again for your input! -- Denisa Tibeica