Is it OK to use DecimalSeparator to force Floattostr/Strtofloat functions to use a decimal point

前端 未结 5 1433
天涯浪人
天涯浪人 2021-01-02 08:29

Currently, I\'m setting DecimalSeparator to a \'.\' in each procedure which uses these functions.

It would be much easier to set this globally at the start of the pr

5条回答
  •  [愿得一人]
    2021-01-02 09:00

    You could patch every string before and after calling a RTL function with some ForceLocalSeparator() and ForceDotSeparator() functions.

    // before a RTL call
    Function ForceLocalSeparator(Const StrValue: String): String;
    Var
      SepPos: Integer;
    Begin
      Result := StrValue;
      If DecimalSeparator <> '.' Then
        Begin
          SepPos := Pos( '.', Result );
          If SepPos > 0 Then Result[SepPos] := DecimalSeparator;
        End;
    End;
    
    // after a RTL call
    Function ForceDotSeparator(Const StrValue: String): String;
    Var
      SepPos: Integer;
    Begin
      Result := StrValue;
      If DecimalSeparator <> '.' Then
        Begin
          SepPos := Pos( DecimalSeparator, Result );
          If SepPos > 0 Then Result[SepPos] := '.';
        End;
    End;
    

提交回复
热议问题