unit uOSVersionAndLocale;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo, FMX.Platform
{$IFDEF Android}
,Androidapi.JNI.Os //TJBuild
,Androidapi.Helpers // StringToJString
{$ENDIF}
{$IFDEF IOS}
,iOSapi.UIKit
,Posix.SysSysctl
,Posix.StdDef
{$ENDIF}
;
type
TForm1 = class(TForm)
Memo1: TMemo;
ToolBar1: TToolBar;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{$IFDEF IOS}
function GetDeviceModelString: String;
{$ENDIF}
{ private }
public
{ public }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
{$IFDEF IOS}
function TForm1.GetDeviceModelString: String;
var
Size: size_t;
DeviceModelBuffer: array of Byte;
begin
sysctlbyname('hw.machine', nil, @Size, nil, 0);
if Size > 0 then
begin
SetLength(DeviceModelBuffer, Size);
sysctlbyname('hw.machine', @DeviceModelBuffer[0], @Size, nil, 0);
Result := UTF8ToString(MarshaledAString(DeviceModelBuffer));
end
else
Result := EmptyStr;
end;
{$ENDIF}
procedure TForm1.Button1Click(Sender: TObject);
var
OSVersion: TOSVersion;
OSLang: String;
LocaleService: IFMXLocaleService;
ModelName: String;
begin
ModelName := 'unknown';
{$IFDEF Android}
ModelName := JStringToString(TJBuild.JavaClass.MODEL);
{$ENDIF}
{$IFDEF IOS}
ModelName := GetDeviceModelString;
{$ENDIF}
Memo1.Lines.Add(Format('ModelName=%s', [ ModelName ] ));
Memo1.Lines.Add(Format('OSName=%s', [OSVersion.Name]));
Memo1.Lines.Add(Format('Platform=%d', [Ord(OSVersion.Platform)]));
Memo1.Lines.Add(Format('Version=%d.%d', [OSVersion.Major,OSVersion.Minor]));
OSLang := '';
if TPlatformServices.Current.SupportsPlatformService(IFMXLocaleService, IInterface(LocaleService)) then
begin
OSLang := LocaleService.GetCurrentLangID();
// if set Japanese on Android, LocaleService returns "jp", but other platform returns "ja"
// so I think it is better to change "jp" to "ja"
if (OSLang = 'jp') then OSLang := 'ja';
end;
Memo1.Lines.Add(Format('Lang=%s', [ OSLang ] ));
end;
end.
The source code of the article is UNREADABLE. It is the source of a HTML formatted text containing the original pascal source.
Oh yes, that was weird, wasn’t it? This is quite an old article from the archives, and it looks like something went wrong when it was copied over in 2017.
I’ve updated it so the code displays correctly now. Sorry about that!