脸红呀!!!有个小问题!!(100分)

  • 主题发起人 benbeng50
  • 开始时间
B

benbeng50

Unregistered / Unconfirmed
GUEST, unregistred user!
如何正确的读取多行文本。并赋给一个一个数组!
我的代码如下:
begin
assignfile(myfile,'D:/Delphi6/program/lottery/data/6.txt');
reset(myfile);
i:=0;
while not eof(myfile) do
begin
readln(myfile,data1[i,0],data1[i,1],data1[i,2],data1[i,3],data1[i,4],data1[i,5],data1[i,6],data1[i,7]);
i:=i+1;
end;
closefile(myfile);
end;
文本如下:
01001 9 8 3 8 0 1 5
01002 5 0 2 1 5 9 7
01003 7 1 9 2 0 9 0
01004 4 0 1 7 9 8 1
01005 0 3 6 2 3 8 7
01006 1 6 2 9 5 7 4
01007 3 9 3 4 3 0 6
01008 2 4 6 9 2 7 7
01009 4 2 7 9 1 2 0
01010 4 5 3 2 6 0 0
01011 2 0 1 8 8 0 1
01012 1 0 4 7 6 8 6
01013 7 8 6 4 1 2 2
01014 0 2 0 8 2 1 7
01015 8 8 3 4 2 8 7
01016 0 9 3 1 1 5 9
01017 8 0 1 5 9 9 4
01018 8 9 4 0 1 3 8
01019 9 0 0 5 7 9 4
01020 5 6 8 6 0 8 4
总是出错!
错误编码为104;
检查时,文本最多只能读8行,接下来就出错了。
请教各大侠!!!
 
myfile定义是什么?
用TStringList读取吧。
 
数组怎么定义的?
 
数组!!!!你定义的长度是多少啊?
 
数组的长度?
 
刚才试了一下, 没问题...
procedure TForm1.Button1Click(Sender: TObject);
var
myfile : TextFile;
i : integer;
data1 : array[0..100, 0..7] of Integer;
begin
assignfile(myfile,'1.txt');
reset(myfile);
i:=0;
while not eof(myfile) do
begin
readln(myfile,data1[i,0],data1[i,1],data1[i,2],data1[i,3],data1[i,4],data1[i,5],data1[i,6],data1[i,7]);
i:=i+1;
end;
closefile(myfile);
end;
 
顶部