试试这个,我刚写的:
读取其中某一行:
procedure TForm1.LoadSomeLine(FileName:string;num:integer;
var Str:string);
var
MyTextFile:TextFile;
MyStr:string;
i:integer;
begin
i:=0;
AssignFile(MyTextFile,FileName);
Reset(MyTextFile);
While not Eof(MyTextFile)do
begin
i:=i+1;
Readln(MyTextFile,MyStr);
if i=num then
begin
Str:=MyStr;
exit;
end;
end;
end;
调用:
procedure TForm1.Button1Click(Sender: TObject);
var
num:integer;
Filename:string;
str:string;
begin
num:=2;
FileName:='d:/aa.txt';
LoadSomeLine(FileName,num,Str);
memo1.Lines.Add(Str);
end;