Re: Copy TStringList to TListBox



On 2 Oct, 23:39, Arjan <ar...@xxxxxxxxxxxxxxx> wrote:
Hello all,

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:


Not quite. Assign copies the values which are in the
TStringList.Objects array.

These are normally pointers to objects (ie a TObject refererence) but
can be any 4-byte value typecast to a TObject.

Hence you can free the TStringList object (itself not its Objects
array) you have Assign(ed) to the listbox, and the listbox still
maintains the original pointers (TObject references) which were in the
TStringList.Objects.

StringList1.Clear; //this changes >=1 objects in ListBox1!

Not in my experience (D3)

.... or have I misunderstood you.

Alan Lloyd
.



Relevant Pages

  • Re: Copy TStringList to TListBox
    ... I have a TStringList containing some strings, ... a separate copy of the Stringlist items. ... but it seems that this only assigns pointers to the original ... These are normally pointers to objects (ie a TObject refererence) but ...
    (comp.lang.pascal.delphi.misc)
  • Re: A taxonomy of types
    ... however, elsewhere in my project (off in the dynamic typesystem, ...), I ... (since I am using NULL-terminated strings), and so I have used U+10FFFF ... remember, C also has things like arrays, funtion pointers, nestable ... int RIL_TypeSmallIntP; ...
    (comp.lang.misc)
  • Re: new IL: C (sort of...).
    ... only for "recent" Pascals, ... far pointers weren't really limited, ... in my compiler, I made wchar_t a builtin type (in most cases, aliased to ... I could very well include builtin "managed strings" in the new IL. ...
    (comp.lang.misc)
  • Re: HeapFree() Failing to deallocate string
    ... I've been able to recreate and isolate the problem with HeapFree(), ... in this simplified example is just a pointer to 16 bytes to store pointers ... the szCaption strings need to be copied to the pointed to ... strings for which storage needs to be allocated, ...
    (microsoft.public.windowsce.embedded)
  • Re: Increasing efficiency in C
    ... >> The representation of a string in C is the sequence of characters, ... strings, they are passed the addresses of strings. ... supports pointers the way it does. ... Competent programmers make mistakes, too. ...
    (comp.lang.c)