|
Notification method in custom components
This applies if the files being scanned contain custom components based on a TComponent (or a component that inherits from a TComponent). Delphi can freeze or become unstable if you reference another component from within this component and you have not included a “Notification” method. A Notification method is normally used to detect that any components being referenced are, in fact, being deleted.
A notification method exists in the “protected” section of your component:
protected
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
The code inside the method should stop any components that this component uses to nil look something like this:
procedure TMyComponent.Notification(AComponent : TComponent;
Operation : TOperation);
begin
inherited Notification(AComponent, Operation);
//If this is the component we are referencing then remove reference
if (Operation = opRemove) and
(AComponent = ReferencedComponent) then
ReferencedComponent := nil
end;
< Back to list of hints and warnings
|