[Resolved] Feature Request need lnDeleting in TList.Notify lazarus / 64-FPC development ---------------------------------------------------------------------- Zaher · 2022-10-22 17:39 I inherited TObjectList, and used TList.Notify to work with my own hash list in the list, I need to recive deleted item before freed by Object List that own that items. lnDeleted is call after this item really deleted and freed, I think  we need new one "lnDeleting" to call before deleting the item. Code: [Select]procedure TList.Delete(Index: Integer); var P : pointer; begin   P:=FList.Get(Index);   if assigned(p) then     Notify(p, lnDeleting);   FList.Delete(Index);   if assigned(p) then     Notify(p, lnDeleted); end; Thank in advance. ---------------------------------------------------------------------- ASerge · 2022-10-23 10:55 Quote from: Zaher on October 22, 2022, 07:39:36 pmI inherited TObjectList, and used TList.Notify to work with my own hash list in the list, I need to recive deleted item before freed by Object List that own that items. lnDeleted is call after this item really deleted and freed, I think  we need new one "lnDeleting" to call before deleting the item. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TMyObjList = class(TObjectList)  protected    procedure Notify(Ptr: Pointer; Action: TListNotification); override;  end; procedure TMyObjList.Notify(Ptr: Pointer; Action: TListNotification);begin  if Action = lnDeleted then    WorkWithItemBeforeFree(Ptr)  else    inherited;end; ---------------------------------------------------------------------- Zaher · 2022-10-24 12:06 Works now thank you so much. I used this in another place, but I have complicated list inheritance and I got crash on removing line, It seem FPC compiler mess with me, It not recompile my changed unit (idk why) I will mark as solved ---------------------------------------------------------------------- Thaddy · 2022-10-24 13:30 The proper way is to use observer/observed: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$MODE OBJFPC}{$APPTYPE CONSOLE} uses Classes; type  TMyObject = class(TObject)  strict private    FName: string;  public    constructor Create(const AName: string);    destructor Destroy; override;  end;   TFreeObjectObserver = class(TInterfacedObject, IFPObserver)    procedure FPOObservedChanged(ASender: TObject; Operation: TFPObservedOperation; Data: Pointer);  end; constructor TMyObject.Create(const AName: string);begin  inherited Create;  FName := AName;end; destructor TMyObject.Destroy;begin  Writeln(#9'Item ''', FName, ''' destroy');  inherited;end; procedure TFreeObjectObserver.FPOObservedChanged(ASender: TObject; Operation: TFPObservedOperation; Data: Pointer);begin  if Operation = ooDeleteItem then    TObject(Data).Free;end; procedure Test;var  L: TList;  Observer: TFreeObjectObserver;begin  Observer := TFreeObjectObserver.Create;  try    L := TList.Create;    try      L.FPOAttachObserver(Observer);      Writeln('Populate list');      L.Add(TMyObject.Create('Zero'));      L.Add(TMyObject.Create('One'));      L.Add(TMyObject.Create('Two'));      L.Add(TMyObject.Create('Three'));      Writeln('Set item 0 to nil');    L[0] := nil;      Writeln('Delete item 2');      L.Delete(2);      Writeln('End of using list');    finally      L.Free;    end;  finally    Observer.Free;  end;end; begin  Test;  Readln;end.This is all standard code and supported by the RTL. Only dependency is classes.