我在处理几万条记录的文本文件,逐条取出插入数据库
if(OpenDialog1.Execute())then
begin
AssignFile(F, OpenDialog1.FileName);
Reset(F);
Label1.Caption:='正在获得文件基本信息';
count:=0;
//得到记录总条数
while not EOF(F) do begin
//Readln(F, S);
//memo1.Lines.Append(S);
count:=count+1;
end;
CloseFile(F);
Reset(F);
i:=0;
while not EOF(F) do begin
Readln(F, S);
//memo1.Lines.Append(S);
i:=i+1;
//此处相应处理每一条记录后,插入数据库
ProgressBar1.Position:=round(i/count)*100;
Label1.Caption:='已经处理'+inttostr(i)+'/'+inttostr(count)+'条记录 ';
end;
end;我加了一个进度条,计算也都正确,可就是每次程序运行的时候程序处于定住的状态,程序上的按钮也都没了反映,进度条自然也不按时刷新,直到所有条数据都处理完了,程序才恢复,进度条此时一下子跳到100%,这样进度条完全失去了意义,请前辈给点建议
if(OpenDialog1.Execute())then
begin
AssignFile(F, OpenDialog1.FileName);
Reset(F);
Label1.Caption:='正在获得文件基本信息';
count:=0;
//得到记录总条数
while not EOF(F) do begin
//Readln(F, S);
//memo1.Lines.Append(S);
count:=count+1;
end;
CloseFile(F);
Reset(F);
i:=0;
while not EOF(F) do begin
Readln(F, S);
//memo1.Lines.Append(S);
i:=i+1;
//此处相应处理每一条记录后,插入数据库
ProgressBar1.Position:=round(i/count)*100;
Label1.Caption:='已经处理'+inttostr(i)+'/'+inttostr(count)+'条记录 ';
end;
end;我加了一个进度条,计算也都正确,可就是每次程序运行的时候程序处于定住的状态,程序上的按钮也都没了反映,进度条自然也不按时刷新,直到所有条数据都处理完了,程序才恢复,进度条此时一下子跳到100%,这样进度条完全失去了意义,请前辈给点建议
while not EOF(F) do begin
//Readln(F, S);
//memo1.Lines.Append(S);
count:=count+1;
end;
-------------------------
错误
while not EOF(F) do begin
Readln(F, S);
//memo1.Lines.Append(S);
count:=count+1;
end;
不读取的话会陷入死循环
---------------------
对于这种操作,在循环的时候需要加:Application.ProcessMessages;我该了你的作了个demo,你看看: www.china-aroma.com/download/progress.rar
问题解决,多谢多谢gamepower111(gamepower111)
没有用到多线程,用到多线程会效率更高吗?