delphi - GetLocaleFormatSettings for LOCALE_INVARIANT returns the users settings under Windows XP German -


all numbers write files exchange purpose use following code:

getlocaleformatsettings(locale_invariant, fsinvariant); floattostrf(value, fsinvariant); 

when read in number use this

getlocaleformatsettings(locale_invariant, fsinvariant); if trystrtofloat(value, floatval, fsinvariant)   result := floatval 

that works under windows 7, incl. german version, fails in german version of windows xp.

the problem seems in getlocaleformatsettings procedure since gives me same values under locale_invariant , locale_default_user.

here code shows issue:

unit umain;  interface  uses   windows, messages, sysutils, variants, classes, graphics, controls, forms,   dialogs, grids, valedit;  type   tform1 = class(tform)     vleditor: tvaluelisteditor;     procedure formshow(sender: tobject);   private     { private declarations }   public     { public declarations }   end;  var   form1: tform1;  implementation  {$r *.dfm}  procedure tform1.formshow(sender: tobject); var   fsinvariant : tformatsettings;   fslocaleuser : tformatsettings; begin   getlocaleformatsettings(locale_invariant, fsinvariant);   vleditor.insertrow('invariant decimal seperator', fsinvariant.decimalseparator, true);   vleditor.insertrow('invariant thousand seperator', fsinvariant.thousandseparator , true);   vleditor.insertrow('invariant list seperator', fsinvariant.listseparator , true);    getlocaleformatsettings(locale_user_default, fslocaleuser);   vleditor.insertrow('locale decimal seperator', fslocaleuser.decimalseparator, true);   vleditor.insertrow('locale thousand seperator', fslocaleuser.thousandseparator, true);   vleditor.insertrow('locale list seperator', fslocaleuser.listseparator, true); end;  end. 

when run exe in windows xp pro - sp3 - german, displays same characters same separators. in german windows 7, shows expected.

what missing here? how come gives different output?

thanks, thomas

update: getlocaleformatsettings checks first if lcid valid using kernel32 function isvalidlcid(lcid, lcid_installed). issue use of lcid_installed rather lcid_supported. locale_invariant supported, not installed on windows xp systems. therefore getlocaleformatsettings routine reverts users lcid.

what best way of fixing it? write own getlocaleformatsettings routine? change code in delphi's sysutils.pas file?

earlier versions of delphi did have problems initializing tformatsettings correctly. instance, d2010 have intialization bug regarding shortmonthnames, longmonthnames, shortdaynames, , longdaynames arrays when specified lcid not installed (but not affect example). there have been formatting-related bug fixes in newer releases.

in cases, calling setthreadlocale() , getformatsettings() in unit's initialization section helps address formatting issues.

fyi, getlocaleformatsettings() deprecated in recent releases, in favor of new tformatsettings.create() method:

procedure tform1.formshow(sender: tobject); var   fsinvariant : tformatsettings;   fslocaleuser : tformatsettings; begin   fsinvariant := tformatsettings.create(locale_invariant);   ...   fslocaleuser := tformatsettings.create(locale_user_default);   ... end; 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -