1Ci Support Help Center home page
Submit a request
Sign in
  1. 1Ci Support
  2. 1C:Enterprise Development Standards
  3. Code conventions
  4. Using 1C:Enterprise language structures

Using compilation directives and preprocessor commands

  • Using 1C:Enterprise language structures
    • General requirements to creating 1C:Enterprise language structures
    • Moving expressions
    • Using duplicate code
    • Using compilation directives and preprocessor commands
    • Defining variable value type
    • Getting objects metadata
    • Form module event handlers attached in code
    • Using global variables in modules
    • Local variables pre-initializing
    • Using event log
See more

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 operation modes.

Incorrect:

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

Incorrect:

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

Correct: 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, don't break code blocks.

© 2020-2021 1C INTERNATIONAL LLC www.1Ci.com Support policy