Ok, here is another version too. I've already posted this in the
German Lazarus forum some times ago. I wrote a dylib-library. You can use the following 2 functions for free.
GetMacOSVersion: function(): CFStringRef; cdecl;
GetMacOSVersion2: function(var systemVersionMajor:SInt32; var systemVersionMinor: SInt32; var systemVersionBugFix:SInt32): CFStringRef; cdecl;
GetMacOSVersion ... returns a localised os version string like "Version 10.6.7 (10J869)"
GetMacOSVersion2 ... returns also the OS version info Major, Minor, Bugfix directly as integer values
The following sample application contains only a TButton and a TMemo:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
dynlibs, MacOSAll, CarbonProc;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
H : TLibHandle;
GetMacOSVersion: function(): CFStringRef; cdecl;
GetMacOSVersion2: function(var systemVersionMajor:SInt32; var systemVersionMinor: SInt32; var systemVersionBugFix:SInt32): CFStringRef; cdecl;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
cfs: CFStringRef;
s: String;
systemVersionMajor, systemVersionMinor, systemVersionBugFix: SInt32;
begin
H := LoadLibrary('/Users/mac/Desktop/getosversion.dylib'); //<------ change here the directory path!!!
pointer(GetMacOSVersion) := GetProcedureAddress(H, 'GetMacOSVersion');
pointer(GetMacOSVersion2) := GetProcedureAddress(H, 'GetMacOSVersion2');
cfs:=GetMacOSVersion();
s:=CFStringToStr(cfs);
Memo1.Lines.Add('Mac Version (System): '+s);
cfs:=GetMacOSVersion2(systemVersionMajor, systemVersionMinor, systemVersionBugFix);
s:=CFStringToStr(cfs);
Memo1.Lines.Add('Mac Version (System): '+s);
Memo1.Lines.Add('Major: '+IntToStr(systemVersionMajor));
Memo1.Lines.Add('Minor: '+IntToStr(systemVersionMinor));
Memo1.Lines.Add('BugFix: '+IntToStr(systemVersionBugFix));
FreeLibrary(H);
end;
end.
As shown above, the USES part should contain "dynlibs, MacOSAll, CarbonProc". If you want to use the sample source above directly, you must change the directory to your real directory in the line of LOADLIBRARY, where the "getosversion.dylib" is located on your harddisk.
jus
P.S.: Sorry for my bad english.
