[fpc-pascal] Basic question about TStringList

Joost van der Sluis joost at cnoc.nl
Thu Mar 27 11:50:24 CET 2008

Op donderdag 27-03-2008 om 11:35 uur [tijdzone +0100], schreef
g.marcou at chimie.u-strasbg.fr:
> Hi,
> I seek help to clarify a very basic use of TStringList.
> Let A and B be TStringLists. What is the difference between:
> A:=B;
> and
> 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.


More information about the fpc-pascal mailing list