
Author: Nikolas M41894
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
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. |

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition
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!