#If...#Endif
From Real Software Documentation
Used to control conditional compilation.
Syntax
#If TargetBoolean [Then] Changed 5.0
//OS specific code
[#Else]
//Other OS-specific code
[#ElseIf TargetBoolean Introduced 5.5]
//Other OS-specific code for this target platform
#Endif
OR
#If TargetBoolean Then OS-specific code
| Part | Type | Description |
|---|---|---|
| TargetBoolean | Boolean constant or Boolean constant expression. | Constant or expression that evaluates to a boolean constant. Used to determine the operating system that will include the code that follows.
The DebugBuild, RBVersion, TargetBigEndian, TargetCarbon, TargetHasGUI, TargetLinux, TargetLittleEndian, TargetMacOS, TargetMachO, TargetPowerPC, TargetWin32, TargetCocoa or TargetX86, TargetWeb constants are used. |
Notes
#If statements can be written on one line if there are no #Else or #Elseif clauses. In this case, the Then keyword is required and the #endif is not part of the syntax.
Use conditional compilation to isolate platform-specific statements such as API calls, AppleEvent routines, or console application routines that are specific to Windows, Mac OS X, or Linux. The code following the #If statement is included only in the build for that operating system.
The optional #ElseIf clause enables you to use a template such as this for handling all cases:
//Windows specific code here
#ElseIf TargetMacOS
//Macintosh code goes here.
#ElseIf TargetLinux
//Linux code goes right here.
#EndIf
The TargetBoolean parameter must be either a Boolean constant or a Boolean constant expression that evaluates to True or False. For example, you can use RBVersion or RBVersionString in a boolean expression that determines the user’s version of Real Studio.
Examples
The following example assigns values to the (user-defined) Separator property of the App class in its Open event handler. It will be used to specify full pathnames that are correct on Windows, Macintosh and Linux.
Separator=""
#ElseIf TargetMacOS
Separator=":"
#ElseIf TargetLinux
Separator="/"
#Endif
See Also
Declare statement, AppleEvent class; DebugBuild, RBVersion, RBVersionString, TargetBigEndian, TargetCarbon, TargetHasGUI, TargetLinux, TargetLittleEndian, TargetMachO, TargetMacOS, TargetPowerPC, TargetWin32, TargetX86, TargetCocoa, TargetWeb constants.
