Re: Copy TStringList to TListBox



In message <78b1374c-a641-42f9-8192-65a07761daaa@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
"alanglloyd@xxxxxxx" <alanglloyd@xxxxxxx> wrote:

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.

[snip]

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

Not in my experience (D3)

.. or have I misunderstood you.


No, my mistake.
I had made a TStringList descendant with a new Clear (overriding the
original) which Frees all the objects, then calls the original Clear. Sorry,
I was confused.

Thanks everyone.
Now I know that Assign only copies pointers, I have mended my code.
Everything works!



Regards,
Arjan
.



Relevant Pages

  • 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)
  • Re: K&R2 Secition 5.9 - major blunders
    ... Would changing 'point to a' to 'point into a' twenty element array be ... > arrays of pointers is to store character strings of diverse ... comparison between what was really happening (arrays of pointers to ... pointer to a string(this probably would confuse beginners)" and ...
    (comp.lang.c)