方法1:list2.addstrings(list1) 特点是:不会清空list2中原有的数据.
方法2:list2.assign(list1) 特点是:会清空list2中原有的数据(直接替换链表节点的值);
-------------------------------------------------------------------------------------------------------
unit Unit6; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TForm6 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form6: TForm6; implementation {$R *.dfm} procedure TForm6.Button1Click(Sender: TObject); var list1, list2, list3: TStringList; begin list1 := TStringList.Create; list2 := TStringList.Create; list3 := TStringList.Create; try list1.Add('a'); list1.Add('b'); list1.Add('c'); list2.Add('1'); list2.AddStrings(list1); list3.Add('2'); list3.Assign(list1); ShowMessage(list1.Text); ShowMessage('留意这里1不会被清空' + sLineBreak + list2.Text); ShowMessage('2会被清空' + sLineBreak + list3.Text); list1.Clear; ShowMessage('由于是堆中数据被复制一份,所以清空list1后,不会影响list2,list3'); ShowMessage('已被清空' + sLineBreak + list1.Text); ShowMessage('不变' + sLineBreak + list2.Text); ShowMessage('不变' + sLineBreak + list3.Text); finally list1.Free; list2.Free; list3.Free; end; end; end.