怎样每一次读一行的读出一个文本文件的全部内容!
var
instring:string;
s:textfile;
begin
assignfile(s,extractfilepath(application.ExeName)+'text.txt');
reset(s);
readln(s,instring);
edit1.Text:=instring;
end;我想每次读一行的读出一个文本文件的全部内容!
但上面的语句只能总是读第一行。第二行老是读不出。
怎么把当前的文本指针移到第二行开头呢!
然后下一次再读出第二行的内容呢!
var
instring:string;
s:textfile;
begin
assignfile(s,extractfilepath(application.ExeName)+'text.txt');
reset(s);
readln(s,instring);
edit1.Text:=instring;
end;我想每次读一行的读出一个文本文件的全部内容!
但上面的语句只能总是读第一行。第二行老是读不出。
怎么把当前的文本指针移到第二行开头呢!
然后下一次再读出第二行的内容呢!
解决方案 »
- stringgrid某个单元格能否实现fiexedrows那样的3D突出显示和具有不可编辑性?
- 初学delphi想问一下两个小问题?在线等待!!!谢谢
- rave报表,急急!!!
- 怎样通过DELPHI窗体标题栏的帮助按钮[bordericons=bihelp]调用帮助文件?
- 请问如何在窗体重创建自己的快捷键
- 如何实现查询前几名?
- 请问如何用Delphi实现读取网上信息?急用
- 如何在delphi form中插入gif动画
- 如何让程序的子窗体始终位于所有其它进程的最前端?
- could not convert variant of type (null) into type(boolean)
- 使用DELPHI版本的调查~~希望大家近来看一下
- 简单的dbgrid问题?
while not s.eof do
begin
readln(s,instring);
end;
instring:string;
s:textfile;
begin
assignfile(s,'d:\abc.asm');
reset(s);
while not eof(s) do
begin
readln(s,instring);
memo1.lines.Add(instring);
end;
closefile(s);
end;
instring:string;
s:textfile;
i:integer;
begin
assignfile(s,'d:\abc.asm');
reset(s);
i:=1;
while not eof(s) do
begin
readln(s,instring);
if i=CurLine then
begin
inc(CurLine);
exit;
end;
inc(i);
end;
closefile(s);
edit1.Text:=instring;
end;
i: Integer;
sl: TStringList;
s: String; //你的字符串
begin
sl := TStringList.Create;
with sl do
try
LoadFromFile('你的文件.txt');
for i:=0 to Count-1 do
s := sl[i]; //获取本行字符串
finally
Free;
end;
end;
用TStringlist来实现 先获得文本的行数 然后读取
一次性读出,而后再处理,即高效,又方便。
var
Form1: TForm1;
S: TextFile;
implementation{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
AssignFile(S, ExtractFilePath(Application.ExeName)+'text.txt');
Reset(S);
end;procedure TForm1.Button1Click(Sender: TObject);
var
InString: string;
begin
if not Eof(S) then
begin
Readln(S, InString);
Edit1.Text := InString;
end;
end;
slist: TStringList;
curIndex: integer; //当前的行号
procedure TForm1.FormCreate(Sender: TObject);
begin
slist := TStringList.create;
slist.loadFromFile('文件名');end;procedure TForm1.Button1Click(Sender: TObject);
begin
resultStr := sList.string(curIndex-1);
Inc(curIndex);end;procedure TForm1.FormDestroy(Sender: TObject);
begin
slist.free;
end;
begin
readln(f);
end;
for i:=CurLine to CurLine+23 do
begin
readln(f,s);
writeln(s);
end;
无能为力。
对于一个上百兆的文件,word会一次读出?