Delphi check OS version

Building apps for multiple operating systems from the very same source code
imposes unique challenges. Your code might be running on iOS or Android.
It only takes two mouse clicks to recompile your app for a different target.
Certain features might exist on a given platform and not be there on other
platforms. Going further, new functionality is constantly being added to
platforms, so we may want to know on which platform and operating
system version your app is being executed.

This can be done with the TOSVersion record type defined in the
System.SysUtils unit. It has a class constructor that instantiates all its fields.
The TOSVersion record type has inner TArchitecture and TPlatform
enumerated types and corresponding public class properties to read the
current operating system architecture, platform, name, and major and minor
numbers. Additionally, we can check major and minor numbers of the service
pack level.

Here’s some code:


TOSArchitectureHelper = record helper for TOSVersion.TArchitecture
 function ToString: string;

TOSPlatformHelper = record helper for TOSVersion.TPlatform
 function ToString: string;

function OSArchToStr(const Value: TOSVersion.TArchitecture): string;
function OSPlatToStr(const Value: TOSVersion.TPlatform): string;


function OSArchToStr(const Value: TOSVersion.TArchitecture): string;
 case Value of
  arIntelX86: Result := 'IntelX86';
  arIntelX64: Result := 'IntelX64';
  arARM32: Result := 'ARM32';
  arARM64: Result := 'ARM64';
  else Result := 'Unknown OS Architecture';

function TOSArchitectureHelper.ToString: string;
 Result := OSArchToStr(self);

function OSPlatToStr(const Value: TOSVersion.TPlatform): string;
 case Value of
  pfWindows: Result := 'Windows';
  pfMacOS: Result := 'MacOS';
  pfiOS: Result := 'iOS';
  pfAndroid: Result := 'Android';
  pfWinRT: Result := 'WinRT';
  pfLinux: Result := 'Linux';
  else Result := 'Unknown OS Platform'

function TOSPlatformHelper.ToString: string;
 Result := OSPlatToStr(self);

Add this unit to the uses clause of the main form. We can additionally define
in the form class a simple Log(s: string) method that will just display a
given string in the memo.

324 risposte a “Delphi check OS version”

  1. The FDA has built an unbiased Drug Safety Oversight Board
    (DSOB) to oversee the management of drug questions of safety and communication towards the public concerning the risks and important things about
    medicines. Of course, the easiest method to identify your problems
    is to find professional help. s Re – Nu with
    Moisture – Loc contact cleaning solution may be blamed by
    some for that outbreak, since 76% of contact lens wearers who contracted fungal keratitis used that particular solution,
    as it holds just a 10% share of the market in lens cleaning solutions.

Lascia un commento

Il tuo indirizzo email non sarà pubblicato.