L
lfpsoft
Unregistered / Unconfirmed
GUEST, unregistred user!
在文本文件里有10多万的邮件地址记录,但有很多重复的,需要去重复的的。
我用了以下的线程来实现,但速度还是很慢,没有用过多线程,请这里的高手帮帮忙啊!
unit MyThread;
interface
uses
Classes,Controls,SysUtils,Forms;
type
TMyThread = class(TThread)
private
{ Private declarations }
protected
procedure Execute;
override;
end;
implementation
uses MainUnit;
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure TMyThread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end;
}
{ TMyThread }
procedure TMyThread.Execute;
var
AList:TStrings;
npos,i:Integer;
begin
{ Place thread code here }
AList := TStringList.Create ;
try
MainForm.Cursor := crHourGlass;
AList.Assign(MainForm.lbIDList.Items);
MainForm.lbIDList.Items.Clear ;
for i:=0 to AList.Count-1do
begin
if Terminated then
break;
MainForm.ProgressBar.Position := i;
nPos := MainForm.lbIDList.Items.IndexOf(AList);
//
if nPos <0 then
begin
MainForm.lbIDList.Items.Add(AList);
MainForm.lbIDList.ItemIndex := MainForm.lbIDList.Count;
end;
end;
finally
MainForm.Cursor := crDefault;
AList.Free ;
end;
end;
end.
我用了以下的线程来实现,但速度还是很慢,没有用过多线程,请这里的高手帮帮忙啊!
unit MyThread;
interface
uses
Classes,Controls,SysUtils,Forms;
type
TMyThread = class(TThread)
private
{ Private declarations }
protected
procedure Execute;
override;
end;
implementation
uses MainUnit;
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure TMyThread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end;
}
{ TMyThread }
procedure TMyThread.Execute;
var
AList:TStrings;
npos,i:Integer;
begin
{ Place thread code here }
AList := TStringList.Create ;
try
MainForm.Cursor := crHourGlass;
AList.Assign(MainForm.lbIDList.Items);
MainForm.lbIDList.Items.Clear ;
for i:=0 to AList.Count-1do
begin
if Terminated then
break;
MainForm.ProgressBar.Position := i;
nPos := MainForm.lbIDList.Items.IndexOf(AList);
//
if nPos <0 then
begin
MainForm.lbIDList.Items.Add(AList);
MainForm.lbIDList.ItemIndex := MainForm.lbIDList.Count;
end;
end;
finally
MainForm.Cursor := crDefault;
AList.Free ;
end;
end;
end.