function delline(n : integer;filename:string):boolean;
var s : Tstrings;
begin
result := true;
s := Tstringlist.create;
try
s.loadfromfile(filename);
s.delete;
s.savetofile(filename);
except
result := false;
s.free
exit;
end;
s.free;
end;
alum说的是对的,但是有一个概念是错的:
TStrings的行是从0开始的,所以要删除第N行,在TStringS中应该为N-1行,
应该为:
function delline(n : integer;filename:string):boolean;
var s : Tstrings;
begin
if (n>0) then
dec;//新加
result := true;
s := Tstringlist.create;
try
s.loadfromfile(filename);
s.delete;
s.savetofile(filename);
except
result := false;
s.free;
exit;
end;
s.free;
end;
alum说的是对的,但是有一个概念是错的:
TStrings的行是从0开始的,所以要删除第N行,在TStringS中应该为N-1行,
应该为:
function delline(n : integer;filename:string):boolean;
var s : Tstrings;
begin
if (n>0) then
dec;//新加
result := true;
s := Tstringlist.create;
try
s.loadfromfile(filename);
s.delete;
s.savetofile(filename);
except
result := false;
s.free;
exit;
end;
s.free;
end;