方法1:list2.addstrings(list1) 特色是:不會清空list2中原有的數據.api
方法2:list2.assign(list1) 特色是:會清空list2中原有的數據(直接替換鏈表節點的值);spa
-------------------------------------------------------------------------------------------------------code
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.