eof()结束不了一个文件,请大家帮忙?
我要将一个文本文件的读取并转换到EXCEL里面,但是现在在读取文本文件时却退不出来了,
while not eof(txtfile2) do
begin
Read(TxtFile2,Ch)
其它打操作
end;
经过调试发现文本文件已经结束了,转换也基本完成了,但是整过程序进入了死循环,退不出来了,
好象not eof(txtfile2)不能判断文件的结束了,怎么回事,各位还有什么其它方法判断文本文件的
结束方法,谢谢了。
[解决办法]
while?not?eof(txtfile2)?do?
??begin
????Readln(TxtFile2,Ch)
????其它打操作
??end;
var
f: TextFile;
s: string;
begin
s := 'c:\delphi_out\writeTest.txt';
try
AssignFile(f, s);
Reset(f);
ShowMessageFmt('%D', [FileSize(f)]);
finally
CloseFile(f);
end;
end;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
f:TextFile;
s:string;
begin
if Opendialog1.Execute then
begin
AssignFile(f,Opendialog1.FileName);
Reset(f);
while not eof(f) do
begin
ReadLn(f,s);
ListBox1.Items.Add(s);
end;
CloseFile(f);
end;
end;
end.