Link to home
Start Free TrialLog in
Avatar of skymag
skymag

asked on

Get Country Info from Regional Settings

I would like to get the Country Information from the Regional Settings. Either some Delphi 4 or 5 code or a component would be appreciated.
Avatar of RBertora
RBertora
Flag of United Kingdom of Great Britain and Northern Ireland image

There is no country setting in the regional settings... only Language, but if that is what you want you can probably work things out from this piece of code:

Rob ;-)

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(inttostr(GetUserDefaultLangID));




  case GetUserDefaultLangID of

(*  for some unknown reason these do not work!!!aargg
    LANG_AFRIKAANS : label1.Caption := 'AFRIKAANS';
    LANG_ICELANDIC : label1.Caption := 'ICELANDIC';
    LANG_ALBANIAN : label1.Caption := 'ALBANIAN';
    LANG_INDONESIAN : label1.Caption := 'INDONESIAN';
    LANG_ARABIC : label1.Caption := 'ARABIC';
    LANG_ITALIAN : label1.Caption := 'ITALIAN';
    LANG_BASQUE : label1.Caption := 'BASQUE';
    LANG_JAPANESE : label1.Caption := 'JAPANESE';
    LANG_BELARUSIAN : label1.Caption := 'BELARUSIAN';
    LANG_KOREAN : label1.Caption := 'KOREAN';
    LANG_BULGARIAN : label1.Caption := 'BULGARIAN';
    LANG_LATVIAN : label1.Caption := 'LATVIAN';
    LANG_CATALAN : label1.Caption := 'CATALAN';
    LANG_LITHUANIAN : label1.Caption := 'LITHUANIAN';
    LANG_CHINESE : label1.Caption := 'CHINESE';
    LANG_NEUTRAL : label1.Caption := 'NEUTRAL';
    LANG_CROATIAN : label1.Caption := 'CROATIAN';
    LANG_NORWEGIAN : label1.Caption := 'NORWEGIAN';
    LANG_CZECH : label1.Caption := 'CZECH';
    LANG_POLISH : label1.Caption := 'POLISH';
    LANG_DANISH : label1.Caption := 'DANISH';
    LANG_PORTUGUESE : label1.Caption := 'PORTUGUESE';
    LANG_DUTCH : label1.Caption := 'DUTCH';
    LANG_ROMANIAN : label1.Caption := 'ROMANIAN';
    LANG_ENGLISH : label1.Caption := 'ENGLISH';
    LANG_RUSSIAN : label1.Caption := 'USSIAN';
    LANG_ESTONIAN : label1.Caption := 'ESTONIAN';
    LANG_FAEROESE : label1.Caption := 'FAEROESE';
    LANG_SLOVAK : label1.Caption := 'SLOVAK';
    LANG_FARSI : label1.Caption := 'FARSI';
    LANG_SLOVENIAN : label1.Caption := 'SLOVENIAN';
    LANG_FINNISH : label1.Caption := 'FINNISH';
    LANG_SPANISH : label1.Caption := 'SPANISH';
    LANG_FRENCH : label1.Caption := 'FRENCH';
    LANG_SWEDISH : label1.Caption := 'SWEDISH';
    LANG_GERMAN : label1.Caption := 'GERMAN';
    LANG_THAI : label1.Caption := 'THAI';
    LANG_GREEK : label1.Caption := 'GREEK';
    LANG_TURKISH : label1.Caption := 'TURKISH';
    LANG_HEBREW : label1.Caption := 'HEBREW';
    LANG_HUNGARIAN : label1.Caption := 'HUNGARIAN';
    LANG_VIETNAMESE : label1.Caption := 'VIETNAMESE';
*)

    2057 : Label1.Caption := 'English United Kingdom';
    1078 : Label1.Caption := 'Afrikaans';
// I got these values by changing the settings and then clicking the button
// to get the constant values.. you can do the same for all the languages..
// what a grind..

  end;
end;

end.
Avatar of Lischke
Lischke

Rob,

of course your case statement works if you consider one point :-) The language ID contains in reality two values: the primary language and the sub language. Look also MakeLangID and channge your statement to:

  case GetUserDefaultLangID and $3FF of

then it works.

skymag,

what information are you interested in? I think Rob is right if you need the country of the system (if one can say this so). By retrieving the system or user language you get the country too. Do you need anything else?

Ciao, Mike
ah, I had considered that but must admit wasn't driven to explore it further.. Thanks for the info Mike.
Rob ;-)
Here is some code that returns a string like "New Zealand (English)":

function TInfoComputer.GetLocale(ALcid: Integer): string;
  var s: string;
  begin
    Result := '[Unknown]';
    SetLength(s, 128);
    if GetLocaleInfo(ALcid, LOCALE_SENGLANGUAGE, PChar(s), 128) > 0 then
      begin
        Result := StrPas(PChar(s));
        if GetLocaleInfo(ALcid, LOCALE_SENGCOUNTRY, PChar(s), 128) > 0 then
          begin
            Result := Format('%s (%s)', [Result, StrPas(PChar(s))]);
          end;
      end;
  end;

Cheers,
Phil.
Nice function Phil!

  showmessage(GetLocale(GetUserDefaultLangID));

points should be yours :-)

Rob;-)
Avatar of skymag

ASKER

Thanx for all the input guys!

Phil, can you lock the question so that I can assign the points to you!
ASKER CERTIFIED SOLUTION
Avatar of philipleighs
philipleighs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial