From 65bca0a26dc68021c1c9c9fab681bbbe5d9e214b Mon Sep 17 00:00:00 2001 From: ivost Date: Tue, 13 Oct 2009 12:22:36 +0000 Subject: [PATCH] * enhanced how observers are notified by subjects on destroying git-svn-id: trunk@13853 - --- rtl/objpas/classes/compon.inc | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/rtl/objpas/classes/compon.inc b/rtl/objpas/classes/compon.inc index eddfe3eaf1..ba4ebd2974 100644 --- a/rtl/objpas/classes/compon.inc +++ b/rtl/objpas/classes/compon.inc @@ -250,6 +250,8 @@ begin FComponentState := FComponentState - [csFreeNotification]; end; end; +{ disabled this code: do we really have to notify the child components also? Each observer + should register itself to it's subject! } {If assigned(FComponents) then For Runner:=0 To FComponents.Count-1 do TComponent(FComponents.Items[Runner]).Notification(AComponent,Operation);} @@ -413,22 +415,16 @@ Destructor TComponent.Destroy; Var I : Integer; - C : TComponent; - + L : TList; begin Destroying; If Assigned(FFreeNotifies) then begin - I := FFreeNotifies.Count-1; - While I >= 0 do - begin - C:=TComponent(FFreeNotifies.Items[I]); - FFreeNotifies.Delete(I); - C.RemoveNotification(self); - C.Notification(self,opRemove); - I:=FFreeNotifies.Count-1; - end; - FreeAndNil(FFreeNotifies); + L := FFreeNotifies; + FFreenotifies:=Nil; + for I := L.Count - 1 downto 0 do + TComponent(FFreeNotifies.Items[I]).Notification(self,opRemove); + L.Free; end; DestroyComponents; If FOwner<>Nil Then FOwner.RemoveComponent(Self);