Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/VCL/Core VCL Classes    [ Add a report in this area ]  
Report #:  42481   Status: Reported
TCustomIniFile.WriteFloat/ReadFloat are Language Setting dependant
Project:  Delphi Build #:  10.0.2288.42451
Version:    10.0 Submitted By:   Horst Reichert
Report Type:  Basic functionality failure Date Reported:  3/13/2007 7:29:19 AM
Severity:    Commonly encountered problem Last Updated:
Platform:    All platforms Internal Tracking #:  
Resolution: None  Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: (2 Total Ratings)
5.00 out of 5
Total Votes: None
Description
As the above class methods use the language setting dependant  methods  FloatToStr(Value) to write and FloatStr() to read values, the result will depend on the Windows language setting of the Decimal separator.
A language independent result could be obtained replacing the DecimalSeparator (Which might be  , ) with the dot writing the value, and using the Val method reading the data.
Steps to Reproduce:
None
Workarounds
None
Attachment
None
Comments

Giel Bremmers at 3/26/2007 3:35:09 PM -
Overriding ReadFloat with this function has solved this problem for me:


function TMyIniFile.ReadFloat(const Section, Name: string; Default: Double): Double;
var Str: String;
    i: integer;
begin
  Str := inherited ReadString(Section, Name, FloatToStr(Default));
  i := pos(',', str);
  if i > 0 then str[i] := '.';  //nederlandse windows zet komma's in inifiles!
  try
    Result := StrToFloat(Str);
  except
    on EConvertError do Result := Default;  //waarom geeft dit toch error met komma's?
    else raise;
  end;
end;

Horst Reichert at 3/26/2007 11:29:11 PM -
I know how to work around this trap.
I do this in a similar way.
The problem is that the Ini component is claiming to store and load floating point/datetime etc values, but is only storing language dependant string representations.
Especially american and english software authors will run into this trap because they normally do not care about.
Borland/Codegear should not provide any language dependant components at all. They should either make a clear warning to the documentation or depreciate those components.

Server Response from: ETNACODE01