Board index » cppbuilder » ListBox->Items->AddObject but how to delete?

ListBox->Items->AddObject but how to delete?


2005-08-05 05:34:26 PM
cppbuilder19
Hi,
I don't know if this is even an issue but I would like help clearing it from
my mind.
I use a TListBox component and to it use the following type of staement
int nMyReference; // This is then assigned a value somwhere else
ListBox1->Items->AddObject("My Item Name", (TObject *) nMyReference);
I can happily get to the nMyReference and do what I need, but on reading
about AddObject in the help files, it suggests that objects are not
destroyed when the ListBox is destroyed. If this is the case, how do I then
destroy the objects I have created?
cheers
 
 

Re:ListBox->Items->AddObject but how to delete?

Markcr wrote:
Quote
If this is the case, how do I then destroy the objects I have created?
In the OnDeletion handler.
Something like:
void __fastcall TFrmSectorViewer
::lvwFileViewDeletion( TObject * Sender,
TListItem * Item)
{
delete static_cast<TYourTypeName *>( Item->Data );
}
Note that if your object is an array you will need to use 'delete[]'.
For myself when I do this I prefer to use a wrapping class even for
simple types. That way if I ever add more information it's less
traumatic.
--
Andrue Cope [TeamB]
[Bicester, Uk]
info.borland.com/newsgroups/guide.html
 

Re:ListBox->Items->AddObject but how to delete?

"Markcr" < XXXX@XXXXX.COM >wrote in message
Quote
reading about AddObject in the help files, it suggests that objects
are not destroyed when the ListBox is destroyed. If this is the case,
how do I then destroy the objects I have created?
You are not storing any actual objects to begin with, so there is nothing
that needs to be freed. That statement only applies if you are storing true
TObject-derived class instances, which you are not doing.
Gambit
 

{smallsort}

Re:ListBox->Items->AddObject but how to delete?

"Andrue Cope [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote
In the OnDeletion handler.
There is no OnDelete event in TListBox. Markcr is not using a TListView.
Gambit
 

Re:ListBox->Items->AddObject but how to delete?

Thank you, over cautious here!
 

Re:ListBox->Items->AddObject but how to delete?

Remy Lebeau (TeamB) wrote:
Quote
>In the OnDeletion handler.

There is no OnDelete event in TListBox. Markcr is not using a
TListView.
Oops, sorry.
--
Andrue Cope [TeamB]
[Bicester, Uk]
info.borland.com/newsgroups/guide.html