在线等 Delphi逐行读取文本文件报错
我使用了一个Tstringlist,结果我的文件行数太多了,(类似于密码字典)几百万行的样子,于是会报错rangecheckerror就是Tstringlist的边界越界...
我使用了一个Tstringlist,结果我的文件行数太多了,(类似于密码字典)几百万行的样子,于是会报错range check error 就是Tstringlist的边界越界了,该怎么处理
代码如下
procedure TForm1.Button4Click(Sender: TObject);
begin
With TOpenDialog.Create(Nil) Do
Begin
Try
Filter := '文本文件|*.TXT';
If Execute Then //弹出选择需要读取的TXT档的对话框
Begin
Edit1.Clear;
afile := FileName;
alist.LoadFromFile(afile); //程式读取TXT档的内容
If alist.Count > 0 Then
Begin
Edit1.Text := alist[0]; //并把TXT档的内容第一行传到TEDIT里
alist.Delete(0);
End;
End;
Finally
Free;
End;
End;
timer3.Enabled:=true;
end;
procedure TForm1.Timer3Timer(Sender: TObject);
begin
doc := WebBrowser1.Document as IHTMLDocument2;
if doc = nil then Exit;
oleObj := doc.all.item('TextBox1', 0) as IHTMLElement2;
oleObj.Value :='1255446';
oleObj := doc.all.item('TextBox2', 0) as IHTMLElement2;
oleObj.Value :=edit1.text;
oleObj := doc.all.item('Button1', 0) as IHTMLElement2;
oleObj.Click;
If alist.Count > 0 Then
Begin
Edit1.Text := alist[0];
alist.Delete(0);
End
Else
Begin
Application.MessageBox('END!', 'message', 64);
timer3.Enabled:=false;
End;
end;
Initialization
alist := TStringList.Create;
Finalization alist.Clear;
alist.Free;
end. 展开
代码如下
procedure TForm1.Button4Click(Sender: TObject);
begin
With TOpenDialog.Create(Nil) Do
Begin
Try
Filter := '文本文件|*.TXT';
If Execute Then //弹出选择需要读取的TXT档的对话框
Begin
Edit1.Clear;
afile := FileName;
alist.LoadFromFile(afile); //程式读取TXT档的内容
If alist.Count > 0 Then
Begin
Edit1.Text := alist[0]; //并把TXT档的内容第一行传到TEDIT里
alist.Delete(0);
End;
End;
Finally
Free;
End;
End;
timer3.Enabled:=true;
end;
procedure TForm1.Timer3Timer(Sender: TObject);
begin
doc := WebBrowser1.Document as IHTMLDocument2;
if doc = nil then Exit;
oleObj := doc.all.item('TextBox1', 0) as IHTMLElement2;
oleObj.Value :='1255446';
oleObj := doc.all.item('TextBox2', 0) as IHTMLElement2;
oleObj.Value :=edit1.text;
oleObj := doc.all.item('Button1', 0) as IHTMLElement2;
oleObj.Click;
If alist.Count > 0 Then
Begin
Edit1.Text := alist[0];
alist.Delete(0);
End
Else
Begin
Application.MessageBox('END!', 'message', 64);
timer3.Enabled:=false;
End;
end;
Initialization
alist := TStringList.Create;
Finalization alist.Clear;
alist.Free;
end. 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询