[DUG] Validating a TListItem exists

Jolyon Smith jsmith at deltics.co.nz
Tue Feb 1 10:59:04 NZDT 2011


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-bounces at delphi.org.nz [mailto:delphi-bounces at 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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20110201/324c6306/attachment.html 


More information about the Delphi mailing list