2009. március 22., vasárnap

How to detect the regional settings of a system


Problem/Question/Abstract:

How to detect the regional settings of a system

Answer:

Here is some sample code to get the language's abbreviated name, e.g.: ENU.

{ ... }
var
  Buffer: PChar;
  Size: integer;
begin
  Size := GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, nil, 0);
  GetMem(Buffer, Size);
  try
    GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, Buffer, Size);
    Result := string(Buffer);
  finally
    FreeMem(Buffer);
  end;
end;

This code gets the current Currency Symbol from Windows' regional settings:

function GetCurrencySymbol: string;
var
  Res: Cardinal;
begin
  Res := GetLocaleInfo(GetUserDefaultLCID, LOCALE_SCURRENCY, nil, 0);
  SetLength(Result, Res);
  Res := GetLocaleInfo(GetUserDefaultLCID, LOCALE_SMONDECIMALSEP, PChar(Result), Res);
  if Res = 0 then
    RaiseLastOSError;
end;

Nincsenek megjegyzések:

Megjegyzés küldése