Badger
Badger

Reputation: 33

GetLocaleInfo - More Help Needed - Delphi XE5

Firstly, I need to know the measurement units being used on a computer so I can set the constant for converting to twips (1440 or 567). I've looked "everywhere" on the web and I'm having trouble working out whether I should be using GetLocaleInfo or GetLocaleInfoEx. Could someone please explain the difference.

Secondly, I found an answer on this forum under "How to read and change the system measurement units in control panel regional and Language advanced settings". It shows code for setting the measurement units but I'm having trouble setting the parameters for getting the info. Could anyone give an example for the appropriate Function (GetLocaleInfo or GetLocaleInfoEx).

Upvotes: 1

Views: 1333

Answers (1)

Sertac Akyuz
Sertac Akyuz

Reputation: 54802

var
  L: array [0..1] of Char;
begin
  Win32Check(GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_IMEASURE, @L, 2));
  if L[0] = '0' then
    // metric
  else
    // US


var
  L: array [0..1] of Char;
const
  LOCALE_NAME_SYSTEM_DEFAULT = '!x-sys-default-locale';
begin
  Win32Check(GetLocaleInfoEx(LOCALE_NAME_SYSTEM_DEFAULT, LOCALE_IMEASURE, @L, 2) <> 0);
  if L[0] = '0' then
    // metric


GetLocaleInfo accepts a locale identifier, GetLocaleInfoEx accepts a locale name. They both retrieve locale information. As documented, for Vista and up, it is suggested to use GetLocaleInfoEx for its support for custom locales.

Upvotes: 2

Related Questions