eof()完事不了一个文件,请大家帮忙
eof()结束不了一个文件,请大家帮忙?
我要将一个文本文件的读取并转换到EXCEL里面,但是现在在读取文本文件时却退不出来了,
while not eof(txtfile2) do
begin
Read(TxtFile2,Ch)
其它打操作
end;
经过调试发现文本文件已经结束了,转换也基本完成了,但是整过程序进入了死循环,退不出来了,
好象not eof(txtfile2)不能判断文件的结束了,怎么回事,各位还有什么其它方法判断文本文件的
结束方法,谢谢了。
------解决方案--------------------
用ReadLn Api
------解决方案--------------------
还有一个可能就是文件没有结束符。。。
------解决方案--------------------
应该不会吧,把其它操作也贴出来
------解决方案--------------------
------解决方案--------------------
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.
我要将一个文本文件的读取并转换到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
------解决方案--------------------
还有一个可能就是文件没有结束符。。。
------解决方案--------------------
应该不会吧,把其它操作也贴出来
------解决方案--------------------
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.