如何解决list index out of bounds(0) ( 积分: 100 )

  • 主题发起人 主题发起人 asdfg1234
  • 开始时间 开始时间
A

asdfg1234

Unregistered / Unconfirmed
GUEST, unregistred user!
var
slAll,slLine: TStringList;
i: Integer;
begin
// OpenDialog1.Execute;
slAll := TStringList.Create;
slLine := TStringList.Create;
slAll.LoadFromFile('e:/aaa.txt');
for i := 0 to slAll.Count-1 do
begin
slLine.Delimiter := ' ';
slLine.DelimitedText := slAll.Strings;
AdoCommand1.CommandText:='insert into ydfmx_tc (ac,tc) values ('+quotedstr(slLine.Strings[0])+','+quotedstr(slLine.Strings[1])+')';
AdoCommand1.Execute;
end;
slAll.Free;
slLine.Free;
end;
文本文件尾部有空行,导入sql时提示list index out of bounds(0),如何处理.
 
for i := 0 to slAll.Count-1 do
begin
if Trim(slAll.Strings)<>'' then //空行则不要处理
begin
slLine.Delimiter := ' ';
slLine.DelimitedText := slAll.Strings;
AdoCommand1.CommandText:='insert into ydfmx_tc (ac,tc) values ('+quotedstr(slLine.Strings[0])+','+quotedstr(slLine.Strings[1])+')';
AdoCommand1.Execute;
end;
end;
 
for i := 0 to slAll.Count-1 do
begin
if Trim(slAll.Strings)<>'' then //空行则不要处理
begin
slLine.Delimiter := ' ';
slLine.DelimitedText := slAll.Strings;
if slLine.count=0 then continue;
AdoCommand1.CommandText:='insert into ydfmx_tc (ac,tc) values ('+quotedstr(slLine.Strings[0])+','+quotedstr(slLine.Strings[1])+')';
AdoCommand1.Execute;
end;
end;
 
改一下楼上的
if slLine.count >= 2 then continue;
 
改一下楼上的楼上
if slLine.count < 2 then continue;
 
后退
顶部