I am trying to get Country in Delphi using GetLocalInfo in Delphi.
I have this code
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
pcLCA:Array[0..20] of Char;
country : String;
Flag: Integer;
begin
country := GetLocaleInfo(LOCALE_USER_DEFAULT, Flag, pcLCA,19);
showmessage(country);
end;
end.
But here is the main issue, When i run it, i am getting this as error
[dcc32 Error] Unit1.pas(33): E2010 Incompatible types: 'string' and 'Integer'
on the GetLocaleInfo Line Please what am I not doing correctly. New to this.
CodePudding user response:
country := GetLocaleInfo(LOCALE_USER_DEFAULT, Flag, pcLCA,19);
From what I can see in your example you are finding an int value and assigning it to country (a string value). You also seem to be using an uninitialized int value Flag in here.
According to documantation on GetLocaleInfo you should use LOCALE_SNAME (the current region name as a string value) as the LCTYPE input as referenced here
int GetLocaleInfoA(
[in] LCID Locale,
[in] LCTYPE LCType,
[out, optional] LPSTR lpLCData,
[in] int cchData
);
So you should try change your line to use the LCTYPE constant value LOCALE_SNAME and see if that helps:
country := GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SNAME, pcLCA,19);
CodePudding user response:
GetGeoInfo return value is int which is incompatible with string.