Because Delphi shows me this error: Undeclared identifier: 'DecimalSeparator'

1

I'm using Delphi Berlin 10.1.2, I just started a new project using the superobject library: link

This library serves to interpret API responses

function FloatToJson(const value: Double): SOString;
var
  p: PSOChar;
begin
  Result := FloatToStr(value);
  if {$if defined(NEED_FORMATSETTINGS)}FormatSettings.{$ifend}DecimalSeparator <> '.' then //Error aqui
  begin
    p := PSOChar(Result);
    while p^ <> #0 do
      if p^ <> SOChar({$if defined(NEED_FORMATSETTINGS)}FormatSettings.{$ifend}DecimalSeparator) then //Error aqui
      inc(p) else
      begin
        p^ := '.';
        Exit;
      end;
  end;
end;

And in this other function:

function CurrToJson(const value: Currency): SOString;
var
  p: PSOChar;
begin
  Result := CurrToStr(value);
  if {$if defined(NEED_FORMATSETTINGS)}FormatSettings.{$ifend}DecimalSeparator <> '.' then //Error aqui
  begin
    p := PSOChar(Result);
    while p^ <> #0 do
      if p^ <> SOChar({$if defined(NEED_FORMATSETTINGS)}FormatSettings.{$ifend}DecimalSeparator) then //Error aqui
      inc(p) else
      begin
        p^ := '.';
        Exit;
      end;
  end;
end;

The error is:

  

Undeclared identifier: 'DecimalSeparator'

Why does this happen?

    
asked by Martini002 21.05.2017 в 19:27
source

1 answer

0

Generically, the error occurs because the compiler does not find the declaration of the identifier DecimalSeparator within the context.

Interpreting the error, what happens is that the version of the library that you are using does not yet support Delphi Berlin, something strange for this height, since it seems to have been abandoned by the author, since the most recent version is still a more than Berlin (Tokyo).

Fortunately, it is easy to make the necessary change yourself.

As far as I could see from the code fragment you publish, for the code to compile in modern versions of Delphi you need to define the symbol of conditional compilation NEED_FORMATSETTINGS

Looking at the source, the change to make is the following: look for this fragment at the beginning of the unit:

    {$if defined(VER230) or defined(VER240)  or defined(VER250) or
         defined(VER260) or defined(VER270)  or defined(VER280)}
      {$define VER210ORGREATER}
      {$define VER230ORGREATER}
    {$ifend}

and change it for this:

    {$if ComilerVersion >= 21}{$define VER210ORGREATER}{ifend}
    {$if ComilerVersion >= 23}{$define VER230ORGREATER}{ifend}

With this change, you will no longer have problems in this or future versions of Delphi.

    
answered by 22.05.2017 в 17:38