读书人

eof()终结不了一个文件请大家帮忙

发布时间: 2013-09-05 16:02:07 作者: rapoo

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;

用ReadLn Api
[解决办法]
还有一个可能就是文件没有结束符。。。
[解决办法]
应该不会吧,把其它操作也贴出来
[解决办法]
引用:
我用filesize(txtfile2)求文件的大小,结果显示的是“
Varible 'self' inaccessible here due to optimization
请问这个是什么意思呢?
怎么解决呢?

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;

[解决办法]
lz用的哪个版本的delphi?
确认是不是文件格式的问题.

ansichar, char
[解决办法]
猜是EXCEL操作内存出错。
[解决办法]
OLE应用错误
[解决办法]
一个文本文件读取的例子
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
ListBox1: TListBox;


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.

读书人网 >.NET

热点推荐