0

I have a TPersistent defined as follows:

  TGlyph = class(TPersistent)
  private
    FOwner: TControl;
    FLayout: TGlyphAlignment;
    FVisible: Boolean;
    FImageIndex: Integer;
    FImages: TImageList;
    ..............
  protected
    procedure Invalidate;
  public
    constructor Create(AOwner: TControl);
    destructor Destroy; override;
    .............
  published
    property ImageIndex: Integer read FImageIndex write SetImageIndex default -1;
    property Images: TImageList read FImages write SetImages;
    .............
  end;

Is it essential to have a notification procedures that assign nil value to FImages field, such as the kind you use for TComponent?

procedure TGlyph.Notification(AComponent: TComponent; Operation: TOperation);
begin
  inherited;
  if (Operation = opRemove) and (AComponent = FImages) then
  begin
    FImages.OnChange := nil;
    FImages := nil;
    Invalidate;
  end;
end; 

if so, how should be written this procedure?

Thank you, Enzo

Sir Rufo
  • 18,395
  • 2
  • 39
  • 73
Enzo Costantini
  • 167
  • 1
  • 9

2 Answers2

0

It depends on how your class is used. The Notification method is not called automatically, only by your own code (or code written by users of your class). So if Notification is never called there is no need in it.

kludg
  • 27,213
  • 5
  • 67
  • 118
0

TPersistent does not support the Notification() system. You need TComponent for that. If TGlyph is used inside of a TComponent that you have also written, then you can have that TComponent handle the notification and update TGlyph when needed. Otherwise, you will have to change TGlyph to derive from TComponent, in which case if TGlyph is used inside a TComponent then just be sure to have TGlyph call SetSubComponent(True) on itself to avoid any Object Inspector and DFM streaming issues.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Thank you very much for your fast answer. I really appreciate your first solution, that has just been implemented and works fine! – Enzo Costantini Dec 31 '12 at 08:39