procedure TForm1.Button1Click(Sender: TObject); var tips:tstringlist; begin tips:=tstringlist.create; tips.loadfromfile('filename.txt'); showmessage(inttostr(tips.Count)); end;
var FileList:TStringList; begin FileList:=TStringList.Creat; Try FileList.Clear; FileList.LoadFromFile('文件名'); ShowMessage('这个文件的行数是'+IntToStr(FileList.Count)) Finally FileList.Free End; 这样写规范一些
procedure TForm1.FileOper(fileName: string); var FileObj:Tstringlist; begin fileobj:=TStringList.Create ; try fileobj.LoadFromFile(fileName); fileobj.Add('这里将增加一个新行'); showmessage(inttostr(fileobj.Count)); '显示行数 //如要删除某一行,如第二行 fileobj.Delete(1); showmessage(inttostr(fileobj.Count)); '显示行数 fileobj.SaveToFile(fileName); finally freeandnil(fileobj); end; end;procedure TForm1.FormCreate(Sender: TObject); begin fileoper('c:\aa.txt') ; end; 测试通过
学生2
学生3
学生4
var
tips:tstringlist;
begin
tips:=tstringlist.create;
tips.loadfromfile('filename.txt');
showmessage(inttostr(tips.Count));
end;
begin
FileList:=TStringList.Creat;
Try
FileList.Clear;
FileList.LoadFromFile('文件名');
ShowMessage('这个文件的行数是'+IntToStr(FileList.Count))
Finally
FileList.Free
End;
这样写规范一些
var
FileObj:Tstringlist;
begin
fileobj:=TStringList.Create ;
try
fileobj.LoadFromFile(fileName);
fileobj.Add('这里将增加一个新行');
showmessage(inttostr(fileobj.Count)); '显示行数
//如要删除某一行,如第二行
fileobj.Delete(1);
showmessage(inttostr(fileobj.Count)); '显示行数
fileobj.SaveToFile(fileName);
finally
freeandnil(fileobj);
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
fileoper('c:\aa.txt') ;
end;
测试通过