Among other enhancements and new features, Xojo 2019r3 introduces the new
System.Version method which, in combination with the
VersionData class, lets us get (and even compare) the current version of the Operating System our Xojo app is running on (macOS, Windows, Linux and iOS).
In some cases it may be of interest to also get the Build Phase of the OS; so I built you a class you can use to get both the Major and Minor version of the OS as the Build Phase on macOS, Windows and iOS. In addition, you can use this class with Xojo releases previous to Xojo 2019r3.
Basically, with this class you’ll be using the same instance (Singleton Design Pattern) to get any of the provided values, or to get the composed string containing all the OS version information ready to be displayed.
To get the values we are interested in, this class calls the
GetVersionExA on Windows (Kernel32 library), while the message invoked on macOS and iOS is
processInfo from the class
Foundation Framework). In order to call the Windows function we need to provide a data structure that will be filled with the required data (among other). Also in this case, the Major and Minor values are the ones published by Microsoft for the
OSVersionInfoA data structure.
So, for example, you can use the following code snippet to get the OS version values and to display the composed string:
Dim majorVersion As Integer = AXOSVersion.MajorVersion Dim minorVersion As Integer = AXOSVersion.MinorVersion Dim buildVersion As Text = AXOSVersion.BuildVersion MessageBox AXOSVersion.VersionString
Observe that the first three lines of code shows how you can get any of the version values, while the last one will display the composed string (you may want to use MsgBox instead of MessageBox on API 1.0 Xojo Releases.)
You can download the AXOSVersion class from this link.
Of course, if you only need to get the Major, Minor and Debug version (and also compare these values against a particular OS version string), then you just need to use
System.Version.ToText on Xojo 2019r3 and later. For example, the following code snippet compares the OS version of the computer our app is running on against a concrete value, so we can execute a block of code or other depending on the result (among other possibilities):
If System.Version >= "10.14.1" Then Else End If
To summarize, in both cases you can get better flexibility in the behaviour of your Xojo apps comparing in run-time the OS version of the computer they are running on! (Xojo 2019r3 and later even works with Linux!)