Delphi 5 - StrToFloat 在 Windows XP 和 Win2K 上的结果不同

标签 delphi delphi-5

我有一个奇怪的问题,我的机器和生产服务器上的字符串转换得到不同的结果,例如:

procedure TForm1.Button1Click(Sender: TObject);
var
   s1: string;
   f1: double;
begin
   s1 := '1.234';
   f1 := StrToFloat(s1); 
end;

procedure TForm1.Button2Click(Sender: TObject);
var
   s2: string;
   f2: double;
begin
   s2 := '1,234';
   f2 := StrToFloat(s2); 
end;

Button1Click 在我的 WinXP 计算机上的结果“1.234”不是有效的浮点值,而在 Win2K 计算机上则工作正常。

另一端的 Button2Click 在我的 WinXP 上表现良好,但确实导致“1,234”不是有效的浮点值错误。

两台机器的区域设置都设置为“德语(奥地利)” - 关于为什么会发生这种情况的任何想法,或者至少为什么区域设置对话框确实显示与 Delphi“DecimalSeparator”和“GetLocaleChar( GetThreadLocale,LOCALE_SDECIMAL,'.')?

问候, 莱因哈特

最佳答案

DecimalSeparator 变量存储区域设置中定义的 Windows 小数分隔符的值。如果要使用 StrToFloat 函数转换的字符串中出现小数点,则它必须与当前的 DecimalSeparator 值匹配。我相信,尽管区域设置匹配,但两个系统中的小数分隔符必须不同。您可以使用此代码检查两个系统中设置的值。

uses
Windows;

procedure TForm1.Button3Click(Sender: TObject);
Var
StrDummy : string;
begin
 StrDummy:='Decimal Separator in Windows '+GetLocaleChar(GetThreadLocale, LOCALE_SDECIMAL, '.')+#13#10+
           'Decimal Separator in Delphi  '+DecimalSeparator;
 ShowMessage(StrDummy);

end;

关于Delphi 5 - StrToFloat 在 Windows XP 和 Win2K 上的结果不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1892041/

相关文章:

Delphi - System.Copy 良好实践

delphi - 在运行时按需更改组件类

delphi - TListView 标题列中的复选框 - 如何防止它窃取焦点?

Delphi:何时重新引入隐藏祖先以及何时显示它们?

delphi - 依靠 DeHL 进行新项目安全吗?

delphi - 如何从 DLL 返回实例?

delphi - Delphi 5和Windows 7问题

delphi - delphi 5 中观察 DBGrid 中选择更改的标准方法是什么?

Delphi XE3 indy tbytes 和 tidbytes 之间的兼容性问题

delphi - 在安装程序中使用 SendNotifyMessage