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.
skymagAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RBertoraCommented:
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.
0
LischkeCommented:
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
0
RBertoraCommented:
ah, I had considered that but must admit wasn't driven to explore it further.. Thanks for the info Mike.
Rob ;-)
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

philipleighsCommented:
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.
1
RBertoraCommented:
Nice function Phil!

  showmessage(GetLocale(GetUserDefaultLangID));

points should be yours :-)

Rob;-)
0
skymagAuthor Commented:
Thanx for all the input guys!

Phil, can you lock the question so that I can assign the points to you!
0
philipleighsCommented:
Oh Great! Thanks,

Cheers,
Phil.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.