Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2020-01

TIniFile.WriteString gives file with BOM, bad

9 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

AlexeyT
         ini_lexmap:= TIniFile.Create(fn_lexmap_final);
         try
           ini_lexmap.WriteString('ref', IntToStr(i_sub), s_lexer);
         finally
           FreeAndNil(ini_lexmap);
         end;

with FPC trunk it converts .ini file to UTF8 BOM! Bad, because then my code reads this .ini file and it cannot find its 1st section: BOMCHARS[ref] is not found, only [ref] is found in original file. So

1) don't write BOM via WriteString

2) if BOM is there, allow ReadString to find section at the file begin: BOMCHARS[ref]

fpc 3.3 r43852 linux x64.

Regards, Alexey

Reply by email

AlexeyT
to Bart
> 2) if BOM is there, allow ReadString to find section at the file begin: I can read/write IniFiles with BOM with fpc r43847, with and withoud DefautSystemCodePage := CP_UTF8.

Sorry, my mistake-- TIniFile can read this BOM file, but my software cannot: a) I've fixed one place where my app reads ini files via TextFile. b) I canNOT fix another place where PYTHON library reads ini file (Python has module for ini files). c) So yes, I want to disable BOM
Regards,
Alexey

Reply by email

AlexeyT
to AlexeyT

Can you add TIniFile.WriteBom property? it's not quite enough, I need to disable it globally in entire app (I have ~10 ini objects), so additional global default is needed (like Lazarus has global variables).

Regards, Alexey

Reply by email

Bart
to AlexeyT
PM AlexeyT wrote
Can you add TIniFile.WriteBom property? it's not quite enough, I need to disable it globally in entire app (I have ~10 ini objects), so additional global default is needed (like Lazarus has global variables).

Open a ticket in the bugtracker?

Bart

Reply by email

Michael Van Canneyt
to AlexeyT:         ini_lexmap:= TIniFile.Create(fn_lexmap_final);         try…
AlexeyT wrote 10 lines
        ini_lexmap:= TIniFile.Create(fn_lexmap_final);         try           ini_lexmap.WriteString('ref', IntToStr(i_sub), s_lexer);         finally           FreeAndNil(ini_lexmap);         end; with FPC trunk it converts .ini file to UTF8 BOM! Bad, because then my code reads this .ini file and it cannot find its 1st section: BOMCHARS[ref] is not found, only [ref] is found in original file. So

I will disable the writing of BOM in TIniFile alltogether.

Michael.

Reply by email

Luca Olivetti
to Michael Van Canneyt

El 11/1/20 a les 0:19, Michael Van Canneyt ha escrit:

Show quoted text 16 lines
On Fri, 10 Jan 2020, AlexeyT via fpc-pascal wrote: >         ini_lexmap:= TIniFile.Create(fn_lexmap_final); >         try >           ini_lexmap.WriteString('ref', IntToStr(i_sub), s_lexer); >         finally >           FreeAndNil(ini_lexmap); >         end; > > with FPC trunk it converts .ini file to UTF8 BOM! Bad, because then my > code reads this .ini file and it cannot find its 1st section: > BOMCHARS[ref] is not found, only [ref] is found in original file. So I will disable the writing of BOM in TIniFile alltogether.

With backward compatibility please (i.e. that after the writing has been disabled TIniFile can still correctly read ini files that already have the BOM).

Bye

Luca

Reply by email

Michael Van Canneyt
to Luca Olivetti
Luca Olivetti wrote 21 lines
El 11/1/20 a les 0:19, Michael Van Canneyt ha escrit: > > > On Fri, 10 Jan 2020, AlexeyT via fpc-pascal wrote: > >>         ini_lexmap:= TIniFile.Create(fn_lexmap_final); >>         try >>           ini_lexmap.WriteString('ref', IntToStr(i_sub), s_lexer); >>         finally >>           FreeAndNil(ini_lexmap); >>         end; >> >> with FPC trunk it converts .ini file to UTF8 BOM! Bad, because then my >> code reads this .ini file and it cannot find its 1st section: >> BOMCHARS[ref] is not found, only [ref] is found in original file. So > > I will disable the writing of BOM in TIniFile alltogether. With backward compatibility please (i.e. that after the writing has been disabled TIniFile can still correctly read ini files that already have the BOM).

Yes. The setting should only affect writing.

Michael.

Reply by email