[fpc-pascal] TInifile does not handle " " (space) as a value.

Michael Van Canneyt michael at freepascal.org
Fri Aug 4 09:47:21 CEST 2017



On Fri, 4 Aug 2017, Torsten Bonde Christiansen wrote:

> Dear List.
>
> I was trying to use the ini file for our program to store a single space 
> " " as a value, but this does not seem to be posible.
>
> From the Wikipedia definition of INI file 
> (https://en.wikipedia.org/wiki/INI_file#Whitespace) whitespace in values 
> does not seem to be well defined, so it may just be a design choice.
>
> The following illustrates the issue:
>
> program Project1;
>
> {$mode objfpc}{$H+}
>
> uses
>   Classes, IniFiles;
>
> var
>   Ini: TIniFile;
>   S: String;
> begin
>   Ini := TIniFile.Create('/tmp/test.ini');
>   Ini.WriteString('sec1', 'S', ' ');
>   Ini.Free;
>
>   Ini := TIniFile.Create('/tmp/test.ini');
>   S := Ini.ReadString('sec1', 'S', 'ZZ'); // S is '' and not ' ' as 
> expected
>   Ini.Free;
> end.
>
>
> Is this considered a bug or "by design"?

This is by design. 
As you said, whitespace is not so well defined.
Probably an option can be added not to trim whitespace, but I fear this will
lead to more inconsistencies.

As a workaround, try quoting your spaces, something like " "

Michael.



More information about the fpc-pascal mailing list