I'm building an application that might have some different tasks depending of the OS which is running it, so I want to know if there is any way to detect the OS and store it in a variable.
Asked
Active
Viewed 182 times
1 Answers
1
Because you have to compile separate executables for each OS, you can just use {$IFDEF}
:
{$IFDEF MACOS} // Mac OSX
{$IFDEF WIN64} // Windows 64 bit
{$IFDEF WIN32} // Windows 32 bit app
{$IFDEF Linux} // Linux
{$IFDEF UNIX} // UNIX
You can differentiate between Win32 and Win64 from a 32-bit app using SysUtils.TOSVersion.Architecture
; the possible values are arIntelX86
and arIntelX64
, and generically (without regard to "bitness") between Windows and MacOS with TOSVersion.Platform
.

Ken White
- 123,280
- 14
- 225
- 444
-
1@Nathan, thanks for the correction to the typo and the additional defines. – Ken White Nov 30 '11 at 20:29
-
macos X is actually define "darwin". "macos" is classic macos, which was also briefly supported. BSD also is defined for all BSDs (now OpenBSD, FreeBSD and Darwin/OSX) – Marco van de Voort Dec 01 '11 at 08:29