[fpc-pascal] Basic question about TStringList
Andreas at TheBergerClan.org
Thu Mar 27 12:35:45 CET 2008
>> I seek help to clarify a very basic use of TStringList.
>> Let A and B be TStringLists. What is the difference between:
>> A.Assign(B); ?
> That's more a basic(?) question about Pascal.
> When you do A:=B; then A has become equal to B. That means for example
> that if you add an new string to B, this new string will also be in A.
> After all A and B are the same.
> Note that if A contained a TStringList that you can not acces it anymore
> through A, but it's still present in memory.
> When you do A.Assign(B); then all strings in A are cleared and
> afterwards all strings in B are copied to A. Further all relevant
> properties of B are also set to A.
> Note that in this case, A should already contain a TStringList, and if
> you add values to B after the assignment, those strings will not appear
> in B.
In other words: When you declare
A, B : TStringList;
you actually allocated two pointer to TStringList since classes are
inherently pointers. When you do "A:=B" you now have A pointing to the
same memory space as B. It's a pity you can't do "A^ := B^;"
More information about the fpc-pascal