Closed bug report

AdomFloat: StrToFloat raises EConvertError on Windows locales with comma decimal separator

Carlos.v Ferri Pereira · ·closed by Colby Knox

altium-bridge 0.2.91 · Altium Designer Professional 25.3.3 (build 25.3.3.23) · Adom Bridge 2.1.279 · Windows 11 (Portuguese/Brazil locale, HKCU\Control Panel\International sDecimal=,)

Summary

On Windows machines whose regional setting uses a comma as the decimal separator (sDecimal = ,, e.g. Portuguese, Spanish, German, French locales), AdomFloat in src/agent/AdomAgent.pas.tmpl validates that the caller string uses an ASCII dot (AdomIsNumber(T, True)) and then calls DelphiScript's StrToFloat(T):

Function AdomFloat(S : String) : Double;
Var
    T : String;
Begin
    Result := 0;
    T := Trim(S);
    If AdomIsNumber(T, True) Then Result := StrToFloat(T)
    Else If gInputError = '' Then gInputError := T;
End;

Because Delphi's StrToFloat uses the OS locale's DecimalSeparator (,), passing '-0.9100' from a .fp.spec in build_footprint (or any other float parameter) raises:

EConvertError
'-0.9100' is not a valid floating point value

Note that line 5896 of AdomAgent.pas.tmpl already noted the output half of this exact locale hazard ({ micrometres as integers: FloatToStr writes a comma decimal on some Windows locales, which breaks JSON }), while AdomFloat on the input side still called StrToFloat(T).

Fix

Parse the validated ASCII sign, integer digits, and . fractional digits directly in AdomFloat (Ord(C) - 48) instead of calling locale-dependent StrToFloat(T).

Workaround verified on the live machine

Setting HKCU\Control Panel\International sDecimal to . (and sThousand to ,) and broadcasting WM_SETTINGCHANGE ("intl") updates Delphi's DecimalSeparator inside the running Altium process immediately without restarting Altium.

errorShot-altium_import_part-1794090657

1 Reply

Colby Knox marked this in progress ·
Colby Knox ·

Fixed in altium-bridge 0.2.92, which is public now: refresh_bridges {"name":"altium"} installs it. Thank you for the precise report and for the fix in PR #4.

The agent now reads every number you pass (-0.9100 in a footprint spec, offsets, board sizes) digit by digit, whatever the Windows decimal separator is. These verbs used to raise EConvertError on a comma locale and now work: build_footprint, footprint_from_land_pattern, import_part, create_footprint, edit_footprint, test_board, board_shape, import_step and add_symbol_art.

We tested it with our test machine set to a comma decimal separator, the same as yours. 0.2.91 failed with '-1.5000' is not a valid floating point value; 0.2.92 passes, and so does the full verb test suite under that setting. You can switch sDecimal back to ,, since the workaround is no longer needed.

If anything else misbehaves with your regional settings, please open a new issue.

Colby Knox closed this ·

Log in to reply.