* Don't use deprecated symbols anymore, silences compilation.

* GetFormatSettings function now can fill an arbitrary TFormatSettings record.

git-svn-id: trunk@17209 -
This commit is contained in:
sergei 2011-03-30 16:20:56 +00:00
parent 5a84a0c4ef
commit d3fe020a55

View File

@ -92,7 +92,7 @@ Const
function setlocale(category: cint; locale: pchar): pchar; cdecl; external clib name 'setlocale'; function setlocale(category: cint; locale: pchar): pchar; cdecl; external clib name 'setlocale';
function nl_langinfo(__item: cint):Pchar;cdecl;external clib name 'nl_langinfo'; function nl_langinfo(__item: cint):Pchar;cdecl;external clib name 'nl_langinfo';
procedure GetFormatSettings; procedure GetFormatSettings(out fmts: TFormatSettings);
function GetLocaleStr(item: cint): string; function GetLocaleStr(item: cint): string;
begin begin
@ -231,56 +231,56 @@ begin
setlocale(__LC_ALL,''); setlocale(__LC_ALL,'');
for i := 1 to 12 do for i := 1 to 12 do
begin begin
ShortMonthNames[i]:=GetLocaleStr(ABMON_1+i-1); fmts.ShortMonthNames[i]:=GetLocaleStr(ABMON_1+i-1);
LongMonthNames[i]:=GetLocaleStr(MON_1+i-1); fmts.LongMonthNames[i]:=GetLocaleStr(MON_1+i-1);
end; end;
for i := 1 to 7 do for i := 1 to 7 do
begin begin
ShortDayNames[i]:=GetLocaleStr(ABDAY_1+i-1); fmts.ShortDayNames[i]:=GetLocaleStr(ABDAY_1+i-1);
LongDayNames[i]:=GetLocaleStr(DAY_1+i-1); fmts.LongDayNames[i]:=GetLocaleStr(DAY_1+i-1);
end; end;
//Date stuff //Date stuff
ShortDateFormat := GetLocaleStr(D_FMT); fmts.ShortDateFormat := GetLocaleStr(D_FMT);
{$ifdef localedebug} {$ifdef localedebug}
OrgFormatSettings.ShortDateFormat:=shortdateformat; OrgFormatSettings.ShortDateFormat:=fmts.shortdateformat;
{$endif} {$endif}
DateSeparator := FindSeparator(ShortDateFormat, DateSeparator); fmts.DateSeparator := FindSeparator(fmts.ShortDateFormat, fmts.DateSeparator);
ShortDateFormat := TransformFormatStr(ShortDateFormat); fmts.ShortDateFormat := TransformFormatStr(fmts.ShortDateFormat);
LongDateFormat := GetLocaleStr(D_T_FMT); fmts.LongDateFormat := GetLocaleStr(D_T_FMT);
{$ifdef localedebug} {$ifdef localedebug}
OrgFormatSettings.LongDateFormat:=longdateformat; OrgFormatSettings.LongDateFormat:=fmts.longdateformat;
{$endif} {$endif}
LongDateFormat := TransformFormatStr(LongDateFormat); fmts.LongDateFormat := TransformFormatStr(fmts.LongDateFormat);
//Time stuff //Time stuff
TimeAMString := GetLocaleStr(AM_STR); fmts.TimeAMString := GetLocaleStr(AM_STR);
TimePMString := GetLocaleStr(PM_STR); fmts.TimePMString := GetLocaleStr(PM_STR);
ShortTimeFormat := GetLocaleStr(T_FMT); fmts.ShortTimeFormat := GetLocaleStr(T_FMT);
{$ifdef localedebug} {$ifdef localedebug}
OrgFormatSettings.ShortTimeFormat:=shorttimeformat; OrgFormatSettings.ShortTimeFormat:=fmts.shorttimeformat;
{$endif} {$endif}
TimeSeparator := FindSeparator(ShortTimeFormat, TimeSeparator); fmts.TimeSeparator := FindSeparator(fmts.ShortTimeFormat, fmts.TimeSeparator);
ShortTimeFormat := TransformFormatStr(ShortTimeFormat); fmts.ShortTimeFormat := TransformFormatStr(fmts.ShortTimeFormat);
LongTimeFormat := GetLocaleStr(T_FMT_AMPM); fmts.LongTimeFormat := GetLocaleStr(T_FMT_AMPM);
{$ifdef localedebug} {$ifdef localedebug}
OrgFormatSettings.LongTimeFormat:=longtimeformat; OrgFormatSettings.LongTimeFormat:=fmts.longtimeformat;
{$endif} {$endif}
if (LongTimeFormat='') then if (fmts.LongTimeFormat='') then
LongTimeFormat:=ShortTimeFormat fmts.LongTimeFormat:=fmts.ShortTimeFormat
else else
LongTimeFormat := TransformFormatStr(LongTimeFormat); fmts.LongTimeFormat := TransformFormatStr(fmts.LongTimeFormat);
{$if defined(BSD) or defined(SUNOS)} {$if defined(BSD) or defined(SUNOS)}
plocale:=localeconv; plocale:=localeconv;
// for these fields there is a separate BSD derived POSIX function. // for these fields there is a separate BSD derived POSIX function.
if not assigned(plocale) then exit; // for now. if not assigned(plocale) then exit; // for now.
CurrencyString:=plocale^.currency_symbol; // int_CURR_SYMBOL (in latin chars) fmts.CurrencyString:=plocale^.currency_symbol; // int_CURR_SYMBOL (in latin chars)
if CurrencyString='' then if fmts.CurrencyString='' then
CurrencyString:=plocale^.int_curr_symbol; fmts.CurrencyString:=plocale^.int_curr_symbol;
CurrencyDecimals:=ord(plocale^.FRAC_DIGITS); fmts.CurrencyDecimals:=ord(plocale^.FRAC_DIGITS);
{$ifdef localedebug} {$ifdef localedebug}
OrgFormatSettings.CurrencyString1:=plocale^.currency_symbol; OrgFormatSettings.CurrencyString1:=plocale^.currency_symbol;
OrgFormatSettings.CurrencyString2:=plocale^.int_curr_symbol; OrgFormatSettings.CurrencyString2:=plocale^.int_curr_symbol;
@ -288,42 +288,42 @@ begin
prec:=ord(plocale^.P_CS_PRECEDES); prec:=ord(plocale^.P_CS_PRECEDES);
sep:=ord(plocale^.P_SEP_BY_SPACE); sep:=ord(plocale^.P_SEP_BY_SPACE);
if (prec<=1) and (sep<=1) then if (prec<=1) and (sep<=1) then
CurrencyFormat := byte(not boolean(prec)) + sep shl 1; fmts.CurrencyFormat := byte(not boolean(prec)) + sep shl 1;
prec := ord(plocale^.N_CS_PRECEDES); prec := ord(plocale^.N_CS_PRECEDES);
sep := ord(plocale^.N_SEP_BY_SPACE); sep := ord(plocale^.N_SEP_BY_SPACE);
signp := ord(plocale^.N_SIGN_POSN); signp := ord(plocale^.N_SIGN_POSN);
if (signp in [0..4]) and (prec in [0, 1]) and (sep in [0, 1]) then if (signp in [0..4]) and (prec in [0, 1]) and (sep in [0, 1]) then
NegCurrFormat := NegFormatsTable[signp, prec, sep]; fmts.NegCurrFormat := NegFormatsTable[signp, prec, sep];
//Number stuff //Number stuff
ThousandSeparator:=plocale^.THOUSANDS_SEP[0]; fmts.ThousandSeparator:=plocale^.THOUSANDS_SEP[0];
{$else} {$else}
//Currency stuff //Currency stuff
CurrencyString := GetLocaleStr(_NL_MONETARY_CRNCYSTR); fmts.CurrencyString := GetLocaleStr(_NL_MONETARY_CRNCYSTR);
{$ifdef localedebug} {$ifdef localedebug}
OrgFormatSettings.CurrencyString1:=currencystring; OrgFormatSettings.CurrencyString1:=fmts.currencystring;
OrgFormatSettings.CurrencyString2:=''; OrgFormatSettings.CurrencyString2:='';
{$endif} {$endif}
CurrencyString := Copy(CurrencyString, 2, Length(CurrencyString)); fmts.CurrencyString := Copy(fmts.CurrencyString, 2, Length(fmts.CurrencyString));
CurrencyDecimals := StrToIntDef(GetLocaleStr(__FRAC_DIGITS), CurrencyDecimals); fmts.CurrencyDecimals := StrToIntDef(GetLocaleStr(__FRAC_DIGITS), fmts.CurrencyDecimals);
prec := byte(GetLocaleChar(__P_CS_PRECEDES)); prec := byte(GetLocaleChar(__P_CS_PRECEDES));
sep := byte(GetLocaleChar(__P_SEP_BY_SPACE)); sep := byte(GetLocaleChar(__P_SEP_BY_SPACE));
if (prec<=1) and (sep<=1) then if (prec<=1) and (sep<=1) then
CurrencyFormat := byte(not boolean(prec)) + sep shl 1; fmts.CurrencyFormat := byte(not boolean(prec)) + sep shl 1;
prec := byte(GetLocaleChar(__N_CS_PRECEDES)); prec := byte(GetLocaleChar(__N_CS_PRECEDES));
sep := byte(GetLocaleChar(__N_SEP_BY_SPACE)); sep := byte(GetLocaleChar(__N_SEP_BY_SPACE));
signp := byte(GetLocaleChar(__N_SIGN_POSN)); signp := byte(GetLocaleChar(__N_SIGN_POSN));
if (signp in [0..4]) and (prec in [0, 1]) and (sep in [0, 1]) then if (signp in [0..4]) and (prec in [0, 1]) and (sep in [0, 1]) then
NegCurrFormat := NegFormatsTable[signp, prec, sep]; fmts.NegCurrFormat := NegFormatsTable[signp, prec, sep];
//Number stuff //Number stuff
ThousandSeparator:=GetLocaleChar(__THOUSANDS_SEP); fmts.ThousandSeparator:=GetLocaleChar(__THOUSANDS_SEP);
Sep := ord(GetLocaleChar(__MON_THOUSANDS_SEP)); Sep := ord(GetLocaleChar(__MON_THOUSANDS_SEP));
if ThousandSeparator=#0 then if fmts.ThousandSeparator=#0 then
ThousandSeparator := char(Sep); fmts.ThousandSeparator := char(Sep);
{$endif} {$endif}
DecimalSeparator:=GetLocaleChar(RADIXCHAR); fmts.DecimalSeparator:=GetLocaleChar(RADIXCHAR);
end; end;
initialization initialization
GetFormatSettings; GetFormatSettings(DefaultFormatSettings);
end. end.