SystemSeekEoln (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

Create data with whitespace at the beginning and end of line to demonstrate that SeekEoln is immune to this.

Code

procedure TForm1.Button1Click(Sender: TObject);
var
   f: System.TextFile;
   j, Y: Integer;
   s: string;
begin
   AssignFile(f,'TEST.TXT');
   Rewrite(f);

   Writeln(f, '    1 2 3 4      ');
   Writeln(f, 'Some text');

   Reset(f);
   Y := 5;

   while not SeekEoln(f) do // Will skip whitespace.
   begin
     Read(f, j);
     Canvas.TextOut(5, Y, IntToStr(j));
     Y := Y + Canvas.TextHeight(IntToStr(j)) + 5;
   end;
   Readln(f); // Read line-end marker.

   Readln(f, s); // Read string with line-end marker.
   Canvas.TextOut(5, Y, s);
end;

Uses