Compilation directives and preprocessor commands

   

Scope: managed applications, mobile applications, and ordinary applications.

1. Use the following compilation directives

&AtClient
&AtServer
&AtServerNoContext

only in managed form modules and command modules. For other modules, use preprocessor commands.

For server-side and client-side common modules, the context is self-evident, so compilation directives are not required. In common modules with client and server flags, compilation directives make it unclear what procedures and functions are available for the module.

2. Do not use preprocessor commands in client/server common modules to identify the contexts (#If Server, #If Client) as it might provide misleading result. Do not place procedures and functions that behave differently on the client and on the server in common modules with the ClientServer postfix. Instead, use the Client and Server postfixes.

Otherwise, it is impossible to guarantee correct operation of client/server procedures and functions in different operation modes.

Incorrect:

Function DefaultLanguageCode() Export
 #If NOT ThinClient AND NOT WebClient Then
 Return Metadata.DefaultLanguage.LanguageCode;
 #Else
 Return StandardSubsystemsClient.ClientParameter("DefaultLanguageCode");
 #EndIf
 EndFunction

Incorrect:

Function DefaultLanguageCode() Export
 #If Server Or ThickClientOrdinaryApplication Or ExternalConnection Then
 Return Metadata.DefaultLanguage.LanguageCode;
 #Else
 Return StandardSubsystemsClient.ClientParameter("DefaultLanguageCode");
 #EndIf
 EndFunction

Instead, create one function in a server module and another function with the same name in a client module. In case these functions have common code, to avoid code duplication, place the common code in a client/server common module, where it can be called from both client and server. By this, you can assure different behavior in client and server contexts without using preprocessor commands.

To adjust your code to different client modes—web, thin, and thick—you can make ad hoc code branches. For example: #If WebClient.

3. Do not place preprocessor commands and data areas in the middle of other code blocks, expressions, or areas where you declare or call procedures or functions.

Incorrect:

Procedure Example1()
 а = 1
 #Region RegionName
 + 2;
 #EndRegion // expression break
 EndProcedure

#Region RegionName
 Procedure Example2()
 // ...
 #EndRegion // procedure break
 EndProcedure

If <...> Then
 // ...
 #If WebClient Then // If-block break
 Else
 // ...
 #EndIf
 EndIf;

Result = Example4(Parameter1,
#If Client Then
 Parameter2, // improper function call
 #EndIf
 Parameter3);

These defects are detected automatically in 1C:Enterprise Development Tools (EDT).

To make proper use of preprocessor commands, do not break code blocks.

   

Icon/Social/001 Icon/Social/006 Icon/Social/005 Icon/Social/004 Icon/Social/002