Class TFreeNotificationObserver

Unit

Declaration

type TFreeNotificationObserver = class(TComponent)

Description

Observe when something is freed, call an event then. You need to set Observed of this component to make it notified about freeing of something. (It will use standard FreeNotification / RemoveFreeNotification under the hood.) When the Observed is freed, this component will make OnFreeNotification event.

Using this is useful if one class wants to observe freeing of multiple properties, and some of those properties may be sometimes equal. In this case using FreeNotification / RemoveFreeNotification with the main class would be unreliable (as RemoveFreeNotification removes the notification, even if you registered to it twice by FreeNotification), and requires complicated code to handles these special cases.

Using this component as a "proxy" to track each property is simpler. See e.g. TCastleThirdPersonNavigation implementation for example.

Hierarchy

  • TObject
  • TPersistent
  • TComponent
  • TFreeNotificationObserver

Overview

Methods

Protected procedure Notification(AComponent: TComponent; Operation: TOperation); override;
Public destructor Destroy; override;

Properties

Public property OnFreeNotification: TFreeNotificationEvent read FOnFreeNotification write FOnFreeNotification;
Public property Observed: TComponent read FObserved write SetObserved;

Description

Methods

Protected procedure Notification(AComponent: TComponent; Operation: TOperation); override;
 
Public destructor Destroy; override;
 

Properties

Public property OnFreeNotification: TFreeNotificationEvent read FOnFreeNotification write FOnFreeNotification;

Called when we receive notification that something was freed.

Public property Observed: TComponent read FObserved write SetObserved;

Setting this property makes the given component observed, freeing it will make OnFreeNotification. When setting, the previous value of this property stops being observed.

Note that this property will be automatically changed to Nil after OnFreeNotification, if the OnFreeNotification will not change it. This is necessary (we need to detach our "free notification" from a component that will be freed) and makes it safer (we will not expose dangling pointer).


Generated by PasDoc 0.15.0.