Preprocessor instructions

Preprocessor instructions are used to specify where procedures and functions of common modules and object modules are available.
Syntax:

   #If <Logical expression> Then
   #ElseIf
<Logical expression> Then
   …
   #Else
   #EndIf

   where:
   <Logical expression> = [NOT] <Preprocessor keyword>[<Boolean operation> [NOT] <Preprocessor keyword> [<Boolean operation> [NOT] <Preprocessor keyword>]…]
   <Preprocessor keyword> = {AtClient | AtServer | ThickClientOrdinaryApplication | ThickClientManagedApplication | Client | Server | ExternalConnection }
  
<Boolean operation> = {AND | OR}

Used terms:

   #If
   #Then
   #ElsIf
   #Else
   #EndIf
   #Region
   #EndRegion
   Client
   AtClient
   AtServer
   MobileAppClient
   MobileAppServer

   ThickClientOrdinaryApplication
   ThickClientManagedApplication
   Server
   ExternalConnection
   ThinClient
   WebClient   
   AND
   OR 
   NOT

The terms are not case-sensitive.

Usage description:

Grouping lines and collapsing line groups in 1C:Enterprise script modules

   #Region [<Region name>]
   …
   #EndRegion

[<Region name>] is the identifier that is displayed as a region title when the region is collapsed.

If the <Region name> is absent, or it is not an identifier, or it consists of several identifiers, a syntax error is reported.

If you do not specify the region name in the module, the following nonlocalizable string will mark a collapsed region: "[.....]".

These preprocessor instructions do not have any effect on the application. When the client module part is generated in a managed application, the instructions are removed from the client module and therefore are not passed to the client application.

Each #Region instruction must have a closing #EndRegion instruction. A module part marked with #Region and #EndRegion instructions cannot overlap with module parts marked with other instructions.
If they do (see the example below), this will cause module compilation errors:

#Region Reg1
…
#If Client Then
…
#EndRegion
…
#EndIf

Preprocessor instructions #Region and #EndRegion can be nested to describe nested regions:

#Region Reg1
…
#Region Reg2
…
…
#EndRegion
…
#EndRegion

Since the only purpose of the #Region and #EndRegion preprocessor instructions is marking 1C:Enterprise script module lines that can be grouped and collapsed, overlapping with other 1C:Enterprise clauses that can be grouped is not supported (such clauses can include procedures and functions, conditional operators, loops, and so on).

Correct:

#Region Reg1
…
Procedure Proc1()
…
EndProcedure
…
#EndRegion

Incorrect (clauses that can be grouped overlap):

#Region Reg1
…
Procedure Proc1()
…
#EndRegion
…
EndProcedure

In client/server mode

If the client/server mode of 1C:Enterprise, you can specify whether specific procedures and functions are executed on the application server or on the client workstation.

   For execution on the server (the Server and AtServer instructions are equivalent):
   #If AtServer Then
   …
   #EndIf

   For the procedure to be available for calling on the server side:

   #If Server Then 
   Procedure Proc1() Export 
   …
   EndProcedure 
   #EndIf

Important! In the above code the ENTIRE procedure, not just some part of it, is inside the block #If Server Then … #EndIf.

When a configuration execution is started, the configuration is loaded and compiled. Common module instances are created both on the server and on the client side. If any of the common modules contains the above code snippet, in compliance with preprocessor instruction #If Server Then … #EndIf it is compiled only on the server side while on the client side this snippet is excluded from the compiled code and the procedure is not available on the client side at all.
Then, upon compilation of the modules that reference this procedure on the client side, the search for the procedure is performed on the client side. The procedure is not available on the client side, so it is not found. Next, the search for the procedure is performed in common modules on the server side where it is found, so all the calls are directed to be executed on the 1C:Enterprise server.

If the block #If Server Then … #EndIf only includes a portion of a procedure, the procedure is available both on the client and on the server side. But on the client side it does not contain the portion enclosed in this block, so the procedure execution result can depend on where the procedure call is processed.

   For execution on the client workstation in ordinary and managed modes:

   #If AtClient Then
   …
   #EndIf

   or

   #If Client Then
   …
   #EndIf

The preprocessor instruction AtClient is defined for all the client applications. To fine-tune a module for a specific client application, there are additional instructions ThickClientOrdinaryApplication, ThickClientManagedApplication, ThinClient, and WebClient, which are defined in their respective applications.
   For execution on the client:

   #If ThickClientOrdinaryApplication Then
   …
   #EndIf
   #If ThickClientManagedApplication Then
   …
   #EndIf

   For execution on the thin client:

   #If ThinClient Then
   …
   #EndIf

   For execution on the web client:

   #If WebClient Then
   …
   #EndIf

In the file mode

In the ordinary client (both in ordinary and managed modes) the following preprocessor instructions are available: AtClient, ClientThickClientOrdinaryApplication, ThickClientManagedApplication, AtServer, and Server.
In the file mode the preprocessor instructions #If Server…, #If Client…, #If ThickClientOrdinaryApplication, and #If ThickClientManagedApplication… are always defined, so a code instance is always available.
In the thin client the following instructions are available: ThinClient, AtClient, and Client.
In the back end of the thin client the following instructions are available: Server and AtServer.
In the external connection, the following instructions are available: ExternalConnection, AtServer, and Server.

In COM connection sessions

To make procedures and functions available in an external connection session, use the ExternalConnection preprocessor instruction.

   #If ExternalConnection Then
   …
   #EndIf

For specifics of using preprocessor instructions together with compilation directives, see Compilation directives.

In mobile applications (client)

To make procedures and functions available in mobile applications on the client side, use the MobileAppClient preprocessor instruction. The directive takes effect independently of Client, i.e. the code is simultaneously Client and MobileAppClient.

   #If MobileAppClient Then
   …
   #EndIf

In mobile applications (server)

To make procedures and functions available in mobile applications on the server side, use the MobileAppServer preprocessor instruction. The directive takes effect independently of Server, i.e. the code is simultaneously Server and MobileAppServer.

   #If MobileAppServer Then
   …
   #EndIf


    

1C:Enterprise Developer's Community