Преглед на файлове

* enhanced how observers are notified by subjects on destroying

git-svn-id: trunk@13853 -
ivost преди 16 години
родител
ревизия
65bca0a26d
променени са 1 файла, в които са добавени 8 реда и са изтрити 12 реда
  1. 8 12
      rtl/objpas/classes/compon.inc

+ 8 - 12
rtl/objpas/classes/compon.inc

@@ -250,6 +250,8 @@ begin
       FComponentState := FComponentState - [csFreeNotification];
       FComponentState := FComponentState - [csFreeNotification];
       end;
       end;
     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
   {If assigned(FComponents) then
     For Runner:=0 To FComponents.Count-1 do
     For Runner:=0 To FComponents.Count-1 do
       TComponent(FComponents.Items[Runner]).Notification(AComponent,Operation);}
       TComponent(FComponents.Items[Runner]).Notification(AComponent,Operation);}
@@ -413,22 +415,16 @@ Destructor TComponent.Destroy;
 
 
 Var
 Var
   I : Integer;
   I : Integer;
-  C : TComponent;
-
+  L : TList;
 begin
 begin
   Destroying;
   Destroying;
   If Assigned(FFreeNotifies) then
   If Assigned(FFreeNotifies) then
     begin
     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;
     end;
   DestroyComponents;
   DestroyComponents;
   If FOwner<>Nil Then FOwner.RemoveComponent(Self);
   If FOwner<>Nil Then FOwner.RemoveComponent(Self);