[fpc-pascal] TIniFile: how to save bool as string?

Michael Van Canneyt michael at freepascal.org
Wed Oct 8 13:40:26 CEST 2014



On Tue, 7 Oct 2014, silvioprog wrote:

> On Tue, Oct 7, 2014 at 3:58 PM, JB <josebenedito at gmail.com> wrote:
>       I usually use integer cast to boolean values, sample:
> 
> [...] 
> 
> But the main ideia to change it is allow any type supported by SysUtils, like integer (-1/0 or 0/1), strings (true/false, yes/no, y/n, sim/não or
> other) etc.
> 
> My patch keeps the current behavior of the INI class, but allows the programmer to internationalize that to the your favorite way. You prefer
> 0/1, I prefer true/false, other prefer yin/yang etc., my patch allow to use in any way. ;)

Unfortunately, this is not quite good enough.

The read part is OK, but we need to make sure that the write part is compatible with other code out there.
It is OK when all code accessing the ini file uses the same conventions but this condition is not always guaranteed.

If your code writes 'true' and my code doesn't handle 'true' because it uses an older version of TIniFile, 
then this is a problem.

So, we'll need a property that tells TIniFile to write using the new properties (by default false), and 
check the value of this property when writing new boolean values.

Michael.


More information about the fpc-pascal mailing list