New in Delphi 12 – GetLinesEnumerator for reading text files line by line

GetLinesEnumerator – New enumerators for reading file content

Returns the line-by-line enumerator without loading full file content into the memory.

Memory Efficiency: TFile.GetLinesEnumerator reads the file line by line, which is memory-efficient for large files. Unlike TFile.ReadLines (which loads all lines into a list), this method streams the file incrementally.

I test it with both ANSI and BOM UTF and it works!

 

Usage:

 for var Line in TFile.GetLinesEnumerator(FileName) do
   Memo1.Lines.Add(Line);

Note: TFileStream can also do something similar by using ReadLine:

while not Reader.EndOfStream do 
  Line := Reader.ReadLine;

Check the LightSaber\ccTextFile.pas on GitHub for similar routines.

Leave a Comment

Scroll to Top