Cannot call StrToFloat with local format settings

When using StrToFloat with a second parameter, which is a local format setting, the compiler gives an error message. Below is an example:

procedure TForm1.ConvertString;
                  i: Integer;
              aReal: Double;
               aStr: UnicodeString;
LocalFormatSettings: TFormatSettings;
begin { TForm1.ConvertString }
  aStr := '1.05';
  LocalFormatSettings := TFormatSettings.Create;
  aReal := **StrToFloat(aStr, LocalFormatSettings)**;
end { TForm1.ConvertString };

The compiler gives the message: "Wrong number of parameters specified for call to "function StrToFloat(String)".

However, the unit System.SysUtils offers both possibilities: only a string or a string and format settings, as can be seen below.

function StrToFloat(const S: string): Extended;
  Result := StrToFloat(S, FormatSettings);

function StrToFloat(const S: string;
  const AFormatSettings: TFormatSettings): Extended;
  if not TextToFloat(S, Result, AFormatSettings) then
    ConvertErrorFmt(@SInvalidFloat, [S]);

Does the compiler use a different System.SysUtils unit? How can I use this second form of StrToFloat?

The question also applies to FloatToStrF and FormatDateTime, which also cannot be used with a format setting parameter.

Add the unit WEBLib.Utils to the uses list.
We added it there as the pas2js team didn't add it yet to the pas2js RTL

Dear Sir,

Thank you for your suggestion. This solves the problem for StrToFloat, but unfortunately introduces a new one for the function IndexOf. The reason being that WebLib.Utils provides less overloaded versions than System.SysUtils. Below are the definitions in both units:



As adding WebLib.Utils hides the overloaded functions in System.SysUtils, I get more errors about the use of IndexOf than with StrToFloat.

By using WebLib.Utils before System.SysUtils, I tried to use the StrToFloat from WebLib.Utils, by explicitly referring to this unit:

StrToFloat(TheStr, v_LocalFormatSettings) becomes WebLib.Utils. StrToFloat(TheStr, v_LocalFormatSettings)

But then the compiler complained about the second parameter, which also must a type from WebLib.Utils. This requires too many adaptations, as I want the original source to be a close as possible to the web version.

So, for the moment, I can live with the limitation on StrToFloat. If necessary, I can encapsulate StrToFloat in a function and call that function, so that the changes remain very local.

Kind regards,

Michel Huybrechts

Micriconsult BV