Copying a Complete String List

From RAD Studio
Jump to: navigation, search

Go Up to Manipulating Strings in a List


You can use the Assign method to copy strings from a source list to a destination list, overwriting the contents of the destination list. To append strings without overwriting the destination list, use AddStrings.

The following example copies the lines from a combo box into a memo (overwriting the memo):

C++:

Memo1->Lines->Assign(ComboBox1->Item)s; //overwrites original strings

Delphi:

 Memo1.Lines.Assign(ComboBox1.Items);    { overwrites original strings }

The following example appends the lines from the combo box to the memo:

C++:

Memo1->Lines->AddStrings(ComboBox1->Items);//appends strings to end

Delphi:

 Memo1.Lines.AddStrings(ComboBox1.Items);   { appends strings to end }

When making local copies of a string list, use the Assign method. If you assign one string-list variable to another:

Delphi:

 StringList1 := StringList2;

the original string-list object will be lost, often with unpredictable results.

See Also