R
richgold
Unregistered / Unconfirmed
GUEST, unregistred user!
检查是否有字段xh,bh值相同之重复记录,如果几千条记录,检查速度太慢,如何提高速度?
程序如下:procedure TForm1.Check_Button2Click(Sender: TObject);
var xh,bh,rd1,errorinfo:string;//字段:rd1:每条记录的序号
mk1:tbookmark;
begin
add_record;//自定义过程:给每一条记录增加序号
table1.first;
errorinfo:='';
Trackbar1.position:=0;//用于显示检查进度
Trackbar1.max:=rd;//rd为总记录数
Trackbar1.frequency:=rd div 10;
edit10.text:=inttostr(Table1.IndexFieldCount);
table1.DisableControls;
while not table1.eof do
begin
mk1:=table1.getbookmark;
rd1:=table1.Fields[0].asstring;
xh:=table1.Fields[1].asstring;
bh:=table1.fields[2].asstring;
table1.Next;
while not table1.eof do
begin
if (xh=table1.fields[1].asstring) and (bh=table1.fields[2].asstring) then
errorinfo:=errorinfo+rd1+'和'+table1.fields[0].asstring+':'+table1.fields[1].asstring+':'+table1.fields[2].asstring+char(13);
table1.next;
end;
table1.gotobookmark(mk1);
table1.Next;
table1.freebookmark(mk1);
Trackbar1.position:=Trackbar1.position+1;
end;
if errorinfo<>'' then
showmessage('以下记录重复:'+char(13)+errorinfo)
else
showmessage('无重复记录,检查完毕!');
table1.EnableControls;
end;
程序如下:procedure TForm1.Check_Button2Click(Sender: TObject);
var xh,bh,rd1,errorinfo:string;//字段:rd1:每条记录的序号
mk1:tbookmark;
begin
add_record;//自定义过程:给每一条记录增加序号
table1.first;
errorinfo:='';
Trackbar1.position:=0;//用于显示检查进度
Trackbar1.max:=rd;//rd为总记录数
Trackbar1.frequency:=rd div 10;
edit10.text:=inttostr(Table1.IndexFieldCount);
table1.DisableControls;
while not table1.eof do
begin
mk1:=table1.getbookmark;
rd1:=table1.Fields[0].asstring;
xh:=table1.Fields[1].asstring;
bh:=table1.fields[2].asstring;
table1.Next;
while not table1.eof do
begin
if (xh=table1.fields[1].asstring) and (bh=table1.fields[2].asstring) then
errorinfo:=errorinfo+rd1+'和'+table1.fields[0].asstring+':'+table1.fields[1].asstring+':'+table1.fields[2].asstring+char(13);
table1.next;
end;
table1.gotobookmark(mk1);
table1.Next;
table1.freebookmark(mk1);
Trackbar1.position:=Trackbar1.position+1;
end;
if errorinfo<>'' then
showmessage('以下记录重复:'+char(13)+errorinfo)
else
showmessage('无重复记录,检查完毕!');
table1.EnableControls;
end;