Re: Copy TStringList to TListBox
- From: Jamie <jamie_ka1lpa_not_valid_after_ka1lpa_@xxxxxxxxxxx>
- Date: Thu, 02 Oct 2008 20:37:48 -0400
Arjan wrote:
Hello all,Ok, I did some looking here.
I have a TStringList containing some strings, with associated objects.
I wish to copy this list to a TListBox, so that the Listbox contains
a separate copy of the Stringlist items (including the objects).
I use Assign, but it seems that this only assigns pointers to the original
objects in the Stringlist instead of copying them to new objects:
ListBox1.Clear;
ListBox1.Items.Assign(StringList1);
StringList1.Clear; //this changes >=1 objects in ListBox1!
(The objects contain a record with string fields, I can watch them in the
debugger. One of the strings of at least one of the objects changes.)
Am I missing something basic?
Regards,
Arjan
the Objects List simply add's the pointer list to reference the
objects. its the same pointers of course, this is why you are
seeing this.
The object array can only hold pointers or integer's etc, so when you did that, it simply copied the pointers which is what it does..
This could lead to some issues if you free those pointers some
where..
You must remember that freeing the TstringList or what ever, does
not clean up the pointers in the object list. Those pointers will
stay alive.!
This is do to the fact that you can use that array to store other
items, not just pointers to objects.
I would say that maybe you should keep a TObjectList lying around
to maintain the original object list. This way, freeing the TObjectList
will also attempt to free the objects in the list.
You can associate them with any object list in the Tstrings classes.
etc..
Now, it's possible the Object array as changed from a Tlist to a TobjectList. If this is the case, this could cause some issues if its allowed to release the objects.. I don't know about this because I haven't explored the source code of newer versions of delphi in some time now. I've been stuck with D7 and waiting for them to produce a
new version that looks ready for mission control apps!
http://webpages.charter.net/jamie_5"
.
- References:
- Copy TStringList to TListBox
- From: Arjan
- Copy TStringList to TListBox
- Prev by Date: Re: Copy TStringList to TListBox
- Next by Date: Re: Copy TStringList to TListBox
- Previous by thread: Re: Copy TStringList to TListBox
- Next by thread: Re: Copy TStringList to TListBox
- Index(es):
Relevant Pages
|