README.md
December 5, 2022 · View on GitHub
Description
This function quickly retrieves a range of lines from a text file.
More Info
| Submitted On | |
| By | Bob Brown |
| Level | Intermediate |
| User Rating | 3.0 (21 globes from 7 users) |
| Compatibility | Delphi 5, Delphi 4, Pre Delphi 4 |
| Category | Delphi function enhancement |
| World | Delphi |
| Archive File |
Source Code
Quickly retrieve the lines from a text file
If you need a quick function to get a line from a text file, try this one. It's very simple to use, for example:
Writeln('The 2nd line in c:\autoexec.bat is '+GetLinesFromFile('c:\autoexec.bat',2,2)[0]);
function GetLinesFromFile(filename:string; linestart, lineend:integer) : TStringList;
(*
// Name : GetLinesFromFile
// Purpose : Returns a series of lines from a text file, starting at linestart and going to lineend
// Date : 12 Feb 2001
// Comments :
*)
var
fn : textfile;
c : word;
Line : String;
begin
Result:=TStringList.Create;
AssignFile(fn,filename);
Reset(fn);
for c:=0 to LineStart do
ReadLn(fn,Line);
for c:=LineStart to LineEnd do
begin
Result.Add(Line);
ReadLn(fn,Line);
end;
CloseFile(fn);
end;
Please vote for this code!