ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage syntax / Structured statements
  • Condition parameter
  • Configuration keyword
  • ConfigurationType keyword
  • Compilations according to the type of strings used (UNICODE or ANSI)
  • Benefits and limitations
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
The <COMPILE IF> statement allows you to compile (or not) a WLanguage code according to a condition.
This statement is mainly used to easily get a multi-configuration code, without displaying any compilation errors (using Configuration and ConfigurationType).
Difference between <COMPILE IF> and the conditional target-code:
  • The conditional target-code compiles the code.
    The conditional target-code is interesting for a component that will be run on different platforms for example. The code is compiled in all the platforms and it will be run according to the current platform. For more details, see Conditional target-code.
  • The conditional compilation (<COMPILE IF> statement) does not compile the code. It is mainly used to avoid displaying the compilation errors (using Configuration and ConfigurationType). For more details, see Benefits and limitations.
Example
<COMPILE IF Configuration <> "Java archive">
Trace("No Java archive")
<END>
<COMPILE IF Configuration <> "Java archive" AND Configuration = "Windows 32-bit executable">
Trace("No Java archive and Exe32")
<END>
<COMPILE IF Configuration = "Linux64" OR ConfigurationType = Android>
Trace("Linux64")
i is int = 12
<ELSE>
Trace("Other")
i is string = 24
<END>


Trace("i = " + i)
// Declare a constant whose value depends on the configuration
<COMPILE IF Configuration <> "Java archive">
CONSTANT
Constant_Name = 10
END
<ELSE>
CONSTANT
Constant_Name = 20
END
<END>
Syntax

Compilation according to a condition

<COMPILE IF <Condition>>
... // Code compiled if the condition is true
<END>

Compiling a code or another one according to a condition

<COMPILE IF <Condition>>
... // Code compiled if the condition is true
<ELSE>
... // Code compiled if the condition is false
<END>

Compiling a code or another one according to several conditions

<COMPILE IF <Condition1>>
... // Code compiled if <Condition1> is true
<SINON IF <Condition2>>
... // Code compiled if <Condition2> is true
...
<SINON IF <ConditionN>>
... // Code compiled if <ConditionN> is true
<END>

Compiling a code or another one according to several conditions

<COMPILE IF <Condition1>>
... // code compiled if <Condition1> is true
<SINON IF <Condition2>>
... // Code compiled if <Condition2> is true
...
<SINON IF <ConditionN>>
... // Code compiled if <ConditionN> is true
<ELSE>
... // Code compiled if all the conditions are false
<END>

Compiling a code according to the types of strings used

<COMPILE IF ConfigurationANSI/ConfigurationUNICODE>
... // code compiled if the current configuration uses ANSI strings or UNICODE strings
<END>

Compiling a code according to the type of configuration used (32 or 64-bit)

<COMPILE IF Configuration32/Configuration64>
... // compiled code if the current configuration is a 32-bit or 64-bit configuration
<END>
Remarks

Condition parameter

The condition must be evaluated during the compilation: therefore, it can only contain literal elements (numbers, strings, True, False, ...) or constants.
Remarks:
  • No function can be used in the condition.
  • The condition can use comparison operators.
  • Specific keywords can be used: Configuration and ConfigurationType.

Configuration keyword

The Configuration keyword returns the name of the current configuration. Therefore, you have the ability to write:
<COMPILE If Configuration = "TestConfig">
// Code compiled in the "TestConfig" configuration
<END>

ConfigurationType keyword

ConfigurationType returns the type of the current configuration. Therefore, you have the ability to write:
<COMPILE IF ConfigurationType=WindowsApplication>
// Code compiled in all the Windows configurations
<END>
The available types of configuration are:
  • WindowsApplication
  • Windows32Application
  • Windows64Application
  • Site
  • Library
  • ExternalComponent
  • Webservice
  • DotNetAssembly
  • DotNetApplication
  • Java
  • LinuxApplication
  • Linux32Application
  • Linux64Application
  • RADPattern
  • WindowsService
  • Windows32Service
  • Windows64Service
  • LinuxService
  • Linux32Service
  • Linux64Service
  • Android
  • ActionPlan
  • iOS
  • MacOSX
  • UniversalWindowsApp
  • WindowsMobile

Compilations according to the type of strings used (UNICODE or ANSI)

The syntax that uses the ANSIConfiguration and UNICODEConfiguration keywords is used to compile a code according to the type of strings used.
This parameter is defined in the description window of the current configuration ("Unicode" tab).
Defining the format of strings

Benefits and limitations

If the conditions specified in <COMPILE IF> are not fulfilled, the WLanguage code is not compiled. The non-compiled code is displayed in gray in the code editor, with a minimum formatting.
Benefits:
  • There is no compilation error: the features specific to each platform (Android, iOS) can be coded without triggering any compilation error in the other configurations.
  • The same variable can be declared in the two parts of a compilation condition with different types.
Limitations: In the non-compiled code:
  • no assisted code input is available.
  • no cross-reference is available: no Shift+F2, the uses of elements are not displayed, the elements can appear in the list of orphan elements and dead code.
  • there is no code analysis: no smart renaming.
  • there is no compilation error: if the prototype of a procedure is modified, the error will be displayed when using a configuration that allows the code compilation.
Minimum version required
  • Version 21
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 10/02/2023

Send a report | Local help