Preprocessor instructions

Source:

Preprocessor instructions are used to specify the place where the code will be executed. Without the Preprocessor instructions, the code will be executed anyway (At Server, At Client, etc.) Instructions can be given for procedures (functions) as a whole or for individual sections of program code. Here is the syntax:

   #If <Logical expression> Then
   <Source Code>
   #ElsIf <Logical expression> Then
   <Source Code>
   #Else
   <Source Code>
   #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 }

And the Keywords:

   #If
   #Then
   #ElsIf
   #Else
   #EndIf
   #Region
   #EndRegion
   Client
   AtClient
   AtServer
   MobileAppClient
   MobileAppServer
   ThickClientOrdinaryApplication
   ThickClientManagedApplication
   Server
   ExternalConnection
   ThinClient
   WebClient  
   AND
   OR
   NOT

Examples:

1)     We can Group lines and collapse them in the Script Module:

#Region [<Region name>]
<Source Code>
#EndRegion 

Regions instructions do not have any effect on the application. instructions cannot overlap with module parts marked with other instructions. These instructions can be nested to describe nested regions.

2)     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.

a.  For execution on the server (the Server and AtServer instructions are equivalent):

#If AtServer Then
<Source Code>
#EndIf

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

#If Server Then 
Procedure Proc1() Export 
<Source Code>
EndProcedure 
#EndIf

In the ordinary client (both in ordinary and managed modes) the following preprocessor instructions are available: AtClient, ClientThickClientOrdinaryApplication, ThickClientManagedApplicationAtServer, 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: ThinClientAtClient, 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: ExternalConnectionAtServer, and Server.


Be the first to know tips & trick on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.