I have a visual component that needs to detect when a collection item has been deleted so it can re-paint.
TCollection has the following protected procedure:
procedure Notify(Item: TCollectionItem; Action: TCollectionNotification); virtual;
Unfortunately it is only called when an item is added and just before it is deleted. I need to know when an item has been deleted.
Internally, TCollection uses a TList that also provides a Notify procedure. The TList version does include a Deleted notification. Unfortunately, the TList is a private member.
How can I detect when a TCollection item has been deleted?
TCollection.Notify()is the correct way to go. Simply don’t repaint immediately,Invalidate()the component instead. By the time the next repaint is actually triggered, the removed item will be gone.