AFAIK when an item is deleted from a listview it is also free'd.
Unavoidably.

 

If you have a reference to a list item that may have been deleted from the
list view, then any attempt to use that reference subsequent to it's being
deleted is likely to fall foul of an access violation (best case: at least
you would get an error to respond to) or be referencing some other memory
that is re-allocated and no longer actually representing the list item it
used to refer to (worst case: since this would be lead to silent unexpected
behaviours).

 

I think the best you can do is add a handler to the Listview.OnDeletion
event and respond to the notifications you will receive at the point at
which any list items are actually deleted.

 

From: delphi-boun...@delphi.org.nz [mailto:delphi-boun...@delphi.org.nz] On
Behalf Of Ross Levis
Sent: Monday, 31 January 2011 16:24
To: 'NZ Borland Developers Group - Delphi List'
Subject: [DUG] Validating a TListItem exists

 

I'm storing some TListItem's in a TList.  Some of these items could be
removed from the listview at some stage.  I know the items should be removed
from the TList when removed from the listview, but don't ask.

 

Is there a simple method to determine if a listitem reference is still valid
and exists, or do I need to use listview.items.indexof which could be slow.

 

Cheers.

_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi@delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: 
unsubscribe

Reply via email to