In my Delphi 10 Seattle app, I am reading a text file (actually an ini file) using TextFile as below:
SDPath := ClientUtils.GetSharedPath;
FileName := TPath.Combine(SDPath, 'Client.ini');
if not MemoVisible then
begin
Panel2.Visible := True;
if FileExists(FileName) then
begin
MemoConfig.Lines.Clear;
AssignFile(T, FileName);
try
Reset(T);
while not Eof(T) do
begin
ReadLn(T, text);
MemoConfig.Lines.Add(text)
end;
finally
CloseFile(T);
end;
end
I noticed that the first line contains [Configuration]
, 3 additional characters that weren't in the original file. I'm guessing this is from when the client.ini file was deployed from my Windows 7 PC. After I have edited the characters out and saved the file with
AssignFile(T, FileName);
try
Rewrite(T);
for i := 0 to MemoConfig.Lines.Count -1 do
WriteLn(T, MemoConfig.Lines[i]);
finally
CloseFile(T)
end;
the file remains correct. Where did the extra characters comes from and what can I do to prevent them from getting into the file?