Procházet zdrojové kódy

* Move move free notifications to separate procedure. Fixes issue #40638

Michaël Van Canneyt před 1 rokem
rodič
revize
d1b7a49700
2 změnil soubory, kde provedl 26 přidání a 22 odebrání
  1. 1 0
      rtl/objpas/classes/classesh.inc
  2. 25 22
      rtl/objpas/classes/compon.inc

+ 1 - 0
rtl/objpas/classes/classesh.inc

@@ -2438,6 +2438,7 @@ type
       Operation: TOperation); virtual;
     procedure PaletteCreated; dynamic;
     procedure ReadState(Reader: TReader); virtual;
+    procedure RemoveFreeNotifications;
     procedure SetAncestor(Value: Boolean);
     procedure SetDesigning(Value: Boolean; SetChildren : Boolean = True);
     procedure SetDesignInstance(Value: Boolean);

+ 25 - 22
rtl/objpas/classes/compon.inc

@@ -329,6 +329,30 @@ begin
   Reader.ReadData(Self);
 end;
 
+procedure TComponent.RemoveFreeNotifications;
+var
+  I: Integer;
+  C: TComponent;
+begin
+  If Assigned(FFreeNotifies) then
+  begin
+    I := FFreeNotifies.Count - 1;
+    while I >= 0 do
+    begin
+      C := TComponent(FFreeNotifies.Items[I]);
+      // Delete, so one component is not notified twice, if it is owned.
+      FFreeNotifies.Delete(I);
+      C.Notification (Self, opRemove);
+      If FFreeNotifies = nil then
+        I := 0
+      else
+        if I > FFreeNotifies.Count then
+          I := FFreeNotifies.Count;
+      Dec(I);
+    end;
+    FreeAndNil(FFreeNotifies);
+  end;
+end;
 
 Procedure TComponent.SetAncestor(Value: Boolean);
 
@@ -472,31 +496,10 @@ end;
 
 
 Destructor TComponent.Destroy;
-
-Var
-  I : Integer;
-  C : TComponent;
-
 begin
   Destroying;
   FreeAndNil(FObservers);
-  If Assigned(FFreeNotifies) then
-    begin
-    I:=FFreeNotifies.Count-1;
-    While (I>=0) do
-      begin
-      C:=TComponent(FFreeNotifies.Items[I]);
-      // Delete, so one component is not notified twice, if it is owned.
-      FFreeNotifies.Delete(I);
-      C.Notification (self,opRemove);
-      If (FFreeNotifies=Nil) then
-        I:=0
-      else if (I>FFreeNotifies.Count) then
-        I:=FFreeNotifies.Count;
-      dec(i);
-      end;
-    FreeAndNil(FFreeNotifies);
-    end;
+  RemoveFreeNotifications;
   DestroyComponents;
   If FOwner<>Nil Then FOwner.RemoveComponent(Self);
   inherited destroy;