ListView.Items.IndexOf() does the trick, so I'll do that in the meantime.

 

Cheers.

 

From: delphi-boun...@delphi.org.nz [mailto:delphi-boun...@delphi.org.nz] On
Behalf Of Jolyon Smith
Sent: Tuesday, 1 February 2011 2:05 PM
To: 'NZ Borland Developers Group - Delphi List'
Subject: Re: [DUG] Validating a TListItem exists

 

If the original item has been Free'd, then it either:

 

a)      Points to nothing (literally, empty unused memory)

or

b)      Points to something else entirely

 

You might be extremely lucky and find that

 

c)      If points to nothing, but the memory previously used for the list
item is entirely or partially temporarily as yet unchanged

 

Whatever you find in one particular case, possibly even in one particular
execution run of that one particular case, is not reliable for every case or
for every execution run.

 

There are ways to do what you wish to do, but I am fairly certain that every
single one will involve more work and more risk than simply assuming that
Anushka has already spilled the oil, and consider a deleted list item as
lost and gone forever, even if it might not be.

 

 

From: delphi-boun...@delphi.org.nz [mailto:delphi-boun...@delphi.org.nz] On
Behalf Of Ross Levis
Sent: Tuesday, 1 February 2011 13:30
To: 'NZ Borland Developers Group - Delphi List'
Subject: Re: [DUG] Validating a TListItem exists

 

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
completely.

 

Cheers.

 

From: delphi-boun...@delphi.org.nz [mailto:delphi-boun...@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.
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