unit Unit1;
{$mode objfpc}{$H+}
{$modeswitch objectivec2}
interface
uses
Classes, SysUtils, Forms, Dialogs, StdCtrls, ExtCtrls,
MacOSAll,
CocoaAll;
type
TForm1 = Class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
counter: Int64;
implementation
{$R *.lfm}
{ TForm1 }
procedure ProcessInfo;
begin
Form1.Memo1.Lines.Clear;
Form1.Memo1.Lines.Add('macOS version: '
+ IntToStr(NSProcessInfo.ProcessInfo.operatingSystemVersion.majorVersion)
+ '.'
+ IntToStr(NSProcessInfo.ProcessInfo.operatingSystemVersion.minorVersion)
+ '.'
+ IntToStr(NSProcessInfo.ProcessInfo.operatingSystemVersion.patchVersion)
);
end;
Procedure GestaltInfo;
var
majorVersion: LongInt = 0;
minorVersion: LongInt = 0;
patchVersion: LongInt = 0;
begin
Form1.Memo1.Lines.Clear;
Form1.Memo1.Lines.Add('Trying another way...');
Gestalt(gestaltSystemVersionMajor, majorVersion);
Gestalt(gestaltSystemVersionMinor, minorVersion);
Gestalt(gestaltSystemVersionBugFix, patchVersion);
Form1.Memo1.Lines.Add('macOS vedrsion: ' + IntToStr(majorVersion) + '.' +
IntToStr(minorVersion) + '.' + IntToStr(patchVersion));
end;
procedure TForm1.Button1Click(Sender: TObject);
var
aSEL : SEL;
begin
// Check whether OS version responds to this selector
aSEL := objcselector('operatingSystemVersion');
if NSProcessInfo.processInfo.respondsToSelector(aSEL) then
processInfo
// Fallback to the deprecated Gestalt function
else
GestaltInfo;
end;
end.