1
0
lazarus-tutorials/text_file/text_file.lpr

48 lines
913 B
ObjectPascal
Raw Normal View History

program text_file;
{$mode objfpc}{$H+}
uses sysutils;
var
txtF: TextFile;
s: String;
procedure ReadTenLines;
const lineNo: integer = 0;
var linesRead: integer = 0;
begin
while not EOF(txtF) and (linesRead < 10) do
begin
ReadLn(txtF, s); // Read the current line in the file, and store in s
Inc(linesRead); // linesRead += 1
Inc(lineNo);
s := Format('Line %d: %s', [lineNo, s]);
WriteLn(s);
end;
end;
begin
AssignFile(txtF, 'text_file.lpr'); // Open pointer to the file
Reset(txtF); // Open existing file
WriteLn('Lines from text_file.lpr will be displayed 10 at a time');
WriteLn;
// Read and display the file
try
while not EOF(txtF) do
begin
ReadTenLines;
WriteLn;
WriteLn('Press [Enter] to continue');
ReadLn;
end;
finally
CloseFile(txtF);
end;
Write('End of file reached. Press [Enter] to finish');
ReadLn;
end.