try
phoneCount := phoneStringList.Count;
//Randomize;
if phoneCount > 0 then
begin
wNum := phoneCount div importCount;
left := phoneCount mod importCount;
importThread1 := importThread.Create(false);
{lvPhone.Items.BeginUpdate;
for i := 0 to phoneStringList.Count - 1 do
begin
tmp := phoneStringList.Strings[i];
li := lvPhone.Items.Add;
li.Caption := tmp;
li.SubItems.Add('');
//randomNum := 10+random(10);
//li.SubItems.Add(IntToStr(randomNum)+':发送成功');
li.SubItems.Add('');
end;
lvPhone.Items.EndUpdate;}
//显示号码条数
StatusBar1.Panels[0].Text := '共有'+IntToStr(phoneCount)+'个客户号码';
end;
finally
//FreeAndNil(phoneStringList);
end;
注释部分是我以前用的方法,很慢。
procedure importThread.Execute;
var
i, j, k:Integer;
randomNum : Integer;
li: TListItem;
tmp: String;
begin
SetName;
FreeOnTerminate := true;
Randomize;
if Form1.wNum > 0 then
begin
for i := 0 to Form1.wNum-1 do
begin
Form1.lvPhone.Items.BeginUpdate;
for j := Form1.importCount*i to Form1.importCount*(i+1)-1 do
begin
tmp := Form1.phoneStringList.Strings[j];
li := Form1.lvPhone.Items.Add;
li.Caption := tmp;
li.SubItems.Add('');
randomNum := 10+random(10);
li.SubItems.Add(IntToStr(randomNum)+':发送成功');
li.SubItems.Add('');
end;
Form1.lvPhone.Items.EndUpdate;
end;
end
else if Form1.left > 0 then
begin
Form1.lvPhone.Items.BeginUpdate;
for k := 0 to Form1.left-1 do
begin
tmp := Form1.phoneStringList.Strings[k];
li := Form1.lvPhone.Items.Add;
li.Caption := tmp;
li.SubItems.Add('');
randomNum := 10+random(10);
li.SubItems.Add(IntToStr(randomNum)+':发送成功');
li.SubItems.Add('');
end;
Form1.lvPhone.Items.EndUpdate;
end;