This function quickly retrieves a range of lines from a text file.
Terms of Agreement:
By using this article, you agree to the following terms...
You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
You may link to this article from another website, but ONLY if it is not wrapped in a frame.
You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
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]);
functionGetLinesFromFile(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;
When I try to use the code I get this error message : [Fatal Error] Unit7.pas(83): Internal error: C862 (If this comment was disrespectful, please report it.)
Add Your Feedback
Your feedback will be posted below and an email sent to
the author. Please remember that the author was kind enough to
share this with you, so any criticisms must be stated politely, or they
will be deleted. (For feedback not related to this particular article, please
click here instead.)