You read each new line in the same variable, thereby overwriting the last line with a new line. If the last read returns an empty string (or a string with just spaces or an enter), your message box will seem empty. And even if it were not empty, it would show only the last line, not the whole file.
Use l as a buffer. After each read, append it to another string:
var l: string;
var t: string;
var f: Textfile;
begin
t := '';
assignfile(f, 'c:\test\file.txt');
reset(f);
while not eof(f) do
begin
readln(f, l);
t := t + l;
end;
closefile(f);
showmessage(t);
For large files it is more efficient to use a String Builder instead of concatting everything to the same string, because t
will be reallocated on each iteration.
Alternatively, use a TStringList or a TFileStream to read files. Using a TFileStream, you can read the whole file at once into a string. The TStringList has the advantage that it parses the file and makes each line an item in the stringlist.
But with those solutions, you are going to read the whole file into memory. If you can process it line by line, do the processing inside the loop.