What defines control CONDITIONAL compilation in Delphi for platform-specific code?
0 reputation · 24 Jan 2024, 08:13 UTC
0 reputation · 24 Jan 2024, 08:13 UTC
The $IFDEF compiler directive enables platform-specific code sections through conditional compilation. Delphi automatically sets platform defines like MSWINDOWS and MSOSX based on the target platform, but the exact set of available defines varies across Delphi versions.
The {$IFDEF CONDITIONAIREDITOR} directive specifically controls visibility of conditional compile-time constants in the IDE. Cross-platform compilation relies on automatic conditional defines such as CLX versus VCL framework detection, though this behavior changed significantly after Delphi 2009.
Conditional defines can be managed through Project Options > Compiler > Defines in the IDE, but the interaction between automatic platform defines and manually specified ones creates potential conflicts. The documentation for which defines are available in each Delphi version remains inconsistent across release notes.
Questions:
Which conditional defines are automatically available when compiling for iOS versus Android targets in Delphi 11?
How does the CONDITIONAIREDITOR define interact with custom conditional defines specified in project options?
What is the complete list of platform-specific defines for macOS compilation in Delphi 10.4+?
35775 reputation · 24 Jan 2024, 20:11 UTC
Delphi automatically defines a mutually exclusive set of top-level platform symbols based on the active target platform. These are the primary controls for conditional compilation:
MSWINDOWS — Windows 32-bit and 64-bit targetsPOSIX — All non-Windows platforms (macOS, iOS, Android, Linux)MACOS — macOS targets (Intel and Apple Silicon)IOS — iOS device and simulator targetsANDROID — Android targetsLINUX — Linux 64-bit targets (x64 in Delphi 11.0–11.2; ARM64 added in 11.3)Framework-level defines further distinguish the UI library: VCL for Windows-only VCL applications and FMX for FireMonkey cross-platform projects. The legacy CLX define (Kylix/Delphi 6–7) is obsolete after Delphi 2009.
Each platform target adds more specific symbols:
| Target | Defines |
|---|---|
| iOS Device | IOS, IOSDEVICE, CPUARM64 |
| iOS Simulator | IOS, IOSSIMULATOR, CPUARM64 (Apple Silicon Mac) or CPUX64 (Intel Mac) |
| Android 64-bit | ANDROID, CPUARM64 |
| Android 32-bit (deprecated in 11) | ANDROID, CPUARM |
| macOS Intel | MACOS, MACOS64, CPUX64 |
| macOS Apple Silicon | MACOS, MACOS64, CPUARM64 |
| Linux x64 (11.0–11.2) | LINUX, CPUX64 |
| Linux ARM64 (11.3+) | LINUX, LINUXARM64, CPUARM64 |
CONDITIONAIREDITOR is an IDE-internal define set only when the conditional compilation editor UI is active. It does not affect compiled output and must not be used in source code for platform logic. Relying on it causes unpredictable IDE behavior and is unsupported.
Defines entered in Project Options → Compiler → Defines are additive with the automatic platform symbols. Conflicts occur only if a custom define explicitly overrides an automatic one (e.g., {$UNDEF MSWINDOWS} or manually defining MSWINDOWS on a non-Windows target), which breaks platform detection. The safe pattern is to only add custom symbols (e.g., MYFEATURE_ENABLED) and never redefine platform symbols.
--defines (e.g., dcciosarm64 --defines).{$IFDEF SYMBOL}{$MESSAGE 'DEFINE: SYMBOL'}{$ENDIF} in a unit to emit active defines during compilation.Define sets change between Delphi versions (10.4, 11.0, 11.3, 12). The RAD Studio documentation for your specific version and the installed System.SysUtils.inc/System.Types.inc in source/rtl/sys/ are the authoritative sources. For production code, verify the active defines on each targeted Delphi version.
One diagnostic detail needed: Which exact Delphi version (e.g., 11.0, 11.3, 12.0) and target platforms are you compiling for? The Linux ARM64 define (LINUXARM64) and iOS simulator CPU define differ across 11.x releases.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.