La clase TStringList es muy útil y muy utilizada por los programadores Delphi, contiene una lista de cadenas. Pero tiene sus fallos.
Uno de ellos es el procedimiento LoadFromFile que, como se indica, carga el contenido de un fichero en la lista. Yo me he encontrado con ficheros que se podían cargar perfectamente con el Notepad, pero el StringList.LoadFromFile no los cargaba correctamente. Por eso me hice este procedimiento que los carga correctamente.
procedure LoadFileToStringList(sl: TStringList; FileName: string);
const
_BuffSize = 4096; // Cargamos en bloques de 4KB
var
c: char;
i: integer;
R: integer;
H: integer;
s: string;
B: PChar;
begin
sl.Clear;
B := PChar(AllocMem(_BuffSize + 1));
H := FileOpen(FileName, fmOpenRead or fmShareExclusive);
if H < 0 then
raise Exception.Create('Error abriendo fichero' + #13#10 + '"' + FileName + '"');
try
repeat
R := FileRead(H, B^, _BuffSize);
for i := 0 to R - 1 do
begin
c := B[i];
if (c in [#13, #10, #0]) then
begin
if (s <> '') then
sl.Add(s);
s := '';
end
else
s := s + c;
end;
until R = 0;
finally
FileClose(H);
FreeMem(B);
end;
end;