Re: [fpc-devel] TIniFile with option ifoWriteStringBoolean

2022-03-17 Thread Armin Linder via fpc-devel

Already filed incident #39625

My way to express the issue was that if you set the 
ifoWriteStringBoolean option but do not assign the string array(s), 
WriteBool will write a string to the ini file which ReadBool cannot 
correctly read back. Furthermore, since the ifoWriteStringBoolean  
option is missing in the documentation, one cannot now.


IMHO, such a behavior is not intentional.

Armin (aka Nimral)

Am 16/03/2022 um 13:04 schrieb Bart via fpc-devel:

Hi,

User Nimral in the wiki noted this:
If you specify ifoWriteStringBoolean in Options for TIniFile _and_ you
forget to assign values to BoolTrueStrings/BoolFalseStrings, then
writing and reading boolean values is not symmetrical.
Writing a boolean will write either 'true' or 'false', but reading
calls CharToBool on the found string.

Consider this piece of code:
   Ini := TIniFile.Create('test.ini');
   Ini.Options := [ifoWriteStringBoolean]; //[ifoWriteStringBoolean]
   Ini.WriteBool('Section','True',True);
   Ini.WriteBool('Section','False',False);
   Ini.Free;

Creates an inifile like:
[Section]
True=true
False=false

Now, with the same options for TIniFile, read the booleans:
   Ini := TIniFile.Create('test.ini');
   Ini.Options := [ifoWriteStringBoolean];
   B := Ini.ReadBool('Section','True',False);
   Check(B, True); //Found FALSE, Expected TRUE: FAIL
   B := Ini.ReadBool('Section','False',True);
   Check(B, False); //Found FALSE, Expected FALSE: OK
   Ini.Free;

I would have expected that, with exactly the same options for
TIniFile, if you read from the ini what you wrote to that ini, you
would get the same value back.

To me, it would have made more sense to either:
- let WriteBool write '1' or '0' if BoolTrueStrings/BoolFalseStrings are empty
or
- let ReadBool compare to 'true' / 'false' if
BoolTrueStrings/BoolFalseStrings are empty
(
or
- initilaze BoolTrueStrings to ['1'] and BoolFalseStrings to ['0']
)

This may very well be Delphi compatible (I cannot test that nor can
find info in Delphi's DocWiki), but if it is not:
Is this by design or is it a bug?

Bart

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] TIniFile with option ifoWriteStringBoolean

2022-03-16 Thread Michael Van Canneyt via fpc-devel




On Wed, 16 Mar 2022, Bart via fpc-devel wrote:


Hi,

User Nimral in the wiki noted this:
If you specify ifoWriteStringBoolean in Options for TIniFile _and_ you
forget to assign values to BoolTrueStrings/BoolFalseStrings, then
writing and reading boolean values is not symmetrical.
Writing a boolean will write either 'true' or 'false', but reading
calls CharToBool on the found string.

Consider this piece of code:
 Ini := TIniFile.Create('test.ini');
 Ini.Options := [ifoWriteStringBoolean]; //[ifoWriteStringBoolean]


It does not say ifoReadStringBoolean or ifoReadWriteStringBoolean for a
reason. So the behaviour is as designed.

The behaviour was introduced for compatibility with other development
environments.

Which is not to say that we cannot change the behaviour.

See
https://gitlab.com/freepascal.org/fpc/source/-/issues/39625

Michael.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] TIniFile with option ifoWriteStringBoolean

2022-03-16 Thread Bart via fpc-devel
Hi,

User Nimral in the wiki noted this:
If you specify ifoWriteStringBoolean in Options for TIniFile _and_ you
forget to assign values to BoolTrueStrings/BoolFalseStrings, then
writing and reading boolean values is not symmetrical.
Writing a boolean will write either 'true' or 'false', but reading
calls CharToBool on the found string.

Consider this piece of code:
  Ini := TIniFile.Create('test.ini');
  Ini.Options := [ifoWriteStringBoolean]; //[ifoWriteStringBoolean]
  Ini.WriteBool('Section','True',True);
  Ini.WriteBool('Section','False',False);
  Ini.Free;

Creates an inifile like:
[Section]
True=true
False=false

Now, with the same options for TIniFile, read the booleans:
  Ini := TIniFile.Create('test.ini');
  Ini.Options := [ifoWriteStringBoolean];
  B := Ini.ReadBool('Section','True',False);
  Check(B, True); //Found FALSE, Expected TRUE: FAIL
  B := Ini.ReadBool('Section','False',True);
  Check(B, False); //Found FALSE, Expected FALSE: OK
  Ini.Free;

I would have expected that, with exactly the same options for
TIniFile, if you read from the ini what you wrote to that ini, you
would get the same value back.

To me, it would have made more sense to either:
- let WriteBool write '1' or '0' if BoolTrueStrings/BoolFalseStrings are empty
or
- let ReadBool compare to 'true' / 'false' if
BoolTrueStrings/BoolFalseStrings are empty
(
or
- initilaze BoolTrueStrings to ['1'] and BoolFalseStrings to ['0']
)

This may very well be Delphi compatible (I cannot test that nor can
find info in Delphi's DocWiki), but if it is not:
Is this by design or is it a bug?

Bart


-- 
Bart
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel