[DUG] Validating a TListItem exists

Ross Levis ross at stationplaylist.com
Tue Feb 1 13:30:19 NZDT 2011

I was hoping to avoid that.  I was thinking there may be a way of validating
that it is still a TListItem the pointer is pointing to, something like an
"is" operation, but it looks like some work required to avoid the issue




From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On
Behalf Of Jolyon Smith
Sent: Tuesday, 1 February 2011 10:59 AM
To: 'NZ Borland Developers Group - Delphi List'
Subject: Re: [DUG] Validating a TListItem exists


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


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


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.



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

More information about the Delphi mailing list