Recent

Author Topic: How to get Country In Pascal  (Read 1062 times)

Nolan

  • New Member
  • *
  • Posts: 15
How to get Country In Pascal
« on: March 15, 2022, 08:54:29 am »
I have a Problem.
I am trying to get the country name (Like 2 letter of country) But i have this trouble - Its nnot working

my code is looking Like this

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Button1: TButton;
  12.     procedure Button1Click(Sender: TObject);
  13.   private
  14.     { Private declarations }
  15.   public
  16.     { Public declarations }
  17.   end;
  18.  
  19. var
  20.   Form1: TForm1;
  21.  
  22. implementation
  23.  
  24. {$R *.dfm}
  25.  
  26. procedure TForm1.Button1Click(Sender: TObject);
  27.   var
  28.   country : String;
  29.   Temp: String;
  30.  
  31. begin
  32.     country := GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SABBREVCTRYNAME, Temp, 256);
  33.     showmessage(country);
  34. end;
  35.  
  36. end.


But i am getting an Error

Code: Pascal  [Select][+][-]
  1. [dcc32 Error] Unit1.pas(32): E2010 Incompatible types: 'PWideChar' and 'string'

On the GetLocalInfo() Line.

Please what is wrong?

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: How to get Country In Pascal
« Reply #1 on: March 15, 2022, 09:12:02 am »
Besides the Fact that GetLocaleInfo returns a LongInt you try to assign to a String?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: How to get Country In Pascal
« Reply #2 on: March 15, 2022, 09:53:42 am »
From sysutils sources:
Code: Pascal  [Select][+][-]
  1. function GetLocaleStr(LID, LT: Longint; const Def: string): AnsiString;
  2. var
  3.   L: Integer;
  4.   Buf: unicodestring;
  5. begin
  6.   L := GetLocaleInfoW(LID, LT, nil, 0);
  7.   if L > 0 then
  8.     begin
  9.       SetLength(Buf,L-1); // L includes terminating NULL
  10.       if l>1 Then
  11.         L := GetLocaleInfoW(LID, LT, @Buf[1], L);
  12.       result:=buf;
  13.     end
  14.   else
  15.     Result := Def;
  16. end;
  17.  

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: How to get Country In Pascal
« Reply #3 on: March 15, 2022, 10:05:45 am »
my code is looking Like this

Code: Pascal  [Select][+][-]
  1. uses
  2.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  3.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
  4.  

But i am getting an Error

Code: Pascal  [Select][+][-]
  1. [dcc32 Error] Unit1.pas(32): E2010 Incompatible types: 'PWideChar' and 'string'

On the GetLocalInfo() Line.

Please what is wrong?
I don't understand this post. I am very sure that this Delphi-like uses clause will not compile here. How then can you report the error about incompatible types? And I've never seen a "dcc32 Error" which looks like a Delphi error. Did you use Delphi to compile your code? Why then do you report the error in a Lazarus forum?

Please make your descriptions as precise as possible. We cannot read your mind.

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: How to get Country In Pascal
« Reply #4 on: March 15, 2022, 10:12:28 am »
And this one gives it away....
Code: Pascal  [Select][+][-]
  1.  
  2. {$R *.dfm}
  3.  
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: How to get Country In Pascal
« Reply #5 on: March 15, 2022, 10:42:00 am »
No, dcc32 and the uses clause give it away. Lazarus can handle dfm too.
« Last Edit: March 15, 2022, 05:51:08 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018