这是我前几天写的一段代码,是把数据读取到StringList里面的。如果要读取到数组里面的话楼主你改一下吧。
procedure TForm1.Button1Click(Sender: TObject);
var
List: TStringList;
i: integer;
id, Date, time, a, temp, c: string;
begin
a := chr(32) + chr(32);
List := TStringList.Create;
try
od.Execute;
List.LoadFromFile(od.FileName); //读取TXT的数据
for i := 0 to List.Count -1 do //从0行开始循环
begin
id := copy(List, 0, pos(a, List) -1); //得到ID
temp := StringReplace(List, id + a, '', [rfReplaceALL]); //把ID外的数据取出来
date := copy(temp, 0, pos(a, temp)-1);
temp := StringReplace(temp, date + a, '', [rfReplaceALL]);
time := copy(temp, 0, pos(a, temp)-1);
temp := StringReplace(temp, time + a, '', [rfReplaceALL]);
c := c + id + chr(9) + date + chr(9) + time + chr(9) + temp + chr(13);
//这里写代码更新到你的数据库表中
end;
ShowMessage(c);
Finally
FreeAndNil(List);
end;
end;