RAD Studio 2007, Windows XP SP2
Is there a way that I could change Regional Settings (mainly date format and
decimal separator) for my program, in Runtime ?
I tried to change these values on each program startup, but DecimalSeparator
remains '.' instead of ',' if my Regional setting was English on program
startup.
CurrencyString:='lei';
CurrencyFormat:=3;
NegCurrFormat:=8;
ThousandSeparator:='.';
DecimalSeparator:=',';
CurrencyDecimals:=2;
SystemDateSeparator:=DateSeparator;
DateSeparator:='.';
ShortDateFormat:='dd.MM.yyyy';
LongDateFormat:='d MMMM yyyy';
TimeSeparator:=':';
ShortTimeFormat:='hh:mm';
LongTimeFormat:='HH:mm:ss';
Thank you,
Tiberiu
> I tried to change these values on each program startup, but DecimalSeparator
> remains '.' instead of ',' if my Regional setting was English on program
> startup.
In which context does DecimalSeparator remain '.'? It's not all
functions that use the DecimalSeparator variable to determine decimal
separator - in some cases it is hardcoded to '.'
If someone else is interested ... :
procedure utils.set_date_curr_format;
var
Locale : LongInt;
changed:Boolean;
begin
changed:=(DecimalSeparator<>',') or
(SubStr(UpperCase(ShortDateFormat),1,2)<>'DD') or
(SubStr(UpperCase(ShortDateFormat),4,2)<>'MM') or
(SubStr(UpperCase(ShortDateFormat),7,4)<>'YYYY') or
(UpperCase(CurrencyString)<>'LEI');
// (UpperCase(LongTimeFormat)<>'HH:MM:SS') or
// Delphi internal variables
CurrencyString:='lei';
CurrencyFormat:=3;
NegCurrFormat:=8;
ThousandSeparator:='.';
DecimalSeparator:=',';
CurrencyDecimals:=2;
SystemDateSeparator:=DateSeparator;
DateSeparator:='.';
ShortDateFormat:='dd.MM.yyyy';
LongDateFormat:='d MMMM yyyy';
TimeSeparator:=':';
ShortTimeFormat:='hh:mm';
LongTimeFormat:='HH:mm:ss';
if changed then begin
// Regional settings - Windows variables
ShowMessage('Regional Settings changed ! ');
Locale := GetUserDefaultLCID(); // 1 Get LCID
// 2 Change the format
// http://msdn2.microsoft.com/en-us/library/bb507201.aspx
SetLocaleInfo(Locale, LOCALE_STIMEFORMAT, PChar(LongTimeFormat));
SetLocaleInfo(Locale, LOCALE_SLONGDATE, PChar(LongDateFormat));
SetLocaleInfo(Locale, LOCALE_SSHORTDATE, PChar(ShortDateFormat));
SetLocaleInfo(Locale, LOCALE_SDECIMAL, PChar(','+chr(0)));
SetLocaleInfo(Locale, LOCALE_STHOUSAND, PChar('.'+chr(0)));
SetLocaleInfo(Locale, LOCALE_SMONDECIMALSEP, PChar(','+chr(0)));
// decimal separator for currency
SetLocaleInfo(Locale, LOCALE_SMONTHOUSANDSEP, PChar('.'+chr(0))); //
thousand separator for currency
SetLocaleInfo(Locale, LOCALE_SCURRENCY, PChar(CurrencyString));
// String used as the local monetary symbol
SetLocaleInfo(Locale, LOCALE_ICURRENCY, PChar('3'+chr(0))); //
Position of the monetary symbol in the positive currency mode Suffix,
1-character separation, for example 1.1 $
SetLocaleInfo(Locale, LOCALE_INEGCURR, PChar('8'+chr(0))); //
Negative sign, number, space, monetary symbol (like #5, but with a space
before the monetary symbol). Example: -1.1 $
SendMessage(HWND_BROADCAST,WM_WININICHANGE,0,0); // 3 Tell the entire
system that the time format has changed
end
end;
"Tiberiu Horvath" <ex...@exactonly.ro> wrote in message
news:47283e3b$1...@newsgroups.borland.com...