Procedure and function execution

Client/server mode
File server mode
COM connection session
Thin client
Web client

Code usage in different run modes may be configured using the preprocessor instructions.

Client/server mode

If you run 1C:Enterprise in client/server mode, you can organize execution of various procedures and functions on the application server or at client's workstation.

To execute on the server:

#If Server Then

#EndIf

To execute on the client's workstation:

#If ThickClientOrdinaryApplication Then

#EndIf

#If ThickClientManagedApplication Then

#EndIf

#If ThinClient Then

#EndIf

To call the procedure from the server and to make it available, use the following syntax:

#If Server Then
Procedure Proc1() Export

EndProcedure
#EndIf

Important! In the sample above, the ENTIRE procedure is located within the #If Server Then ... #EndIf block.
When you launch the configuration for execution, it is loaded and compiled. The system creates instances of all shared modules both on the client side and on the server side. If any shared module contains a similar fragment of code, it will be compiled in accordance with the #If Server Then ... #EndIf preprocessor instruction on the server side only. On the client side this fragment will not be included in compilation, and therefore the procedure will not be available at the client side at all.

When you compile client modules that call this procedure, the system will search for it on the client side. This procedure will not exist on the client side and therefore the system won't find it. Then the system will search for the procedure in the shared modules on the server side. When the procedure is found, all calls to this procedure will be redirected to the 1C:Enterprise server.

If the #If Server Then ... #EndIf block includes only a part of a procedure, this procedure will be available both on the client side and on the server side. A client-side instance of the procedure will not contain the part enclosed within this block. Therefore, the procedure's execution result may depend on the location of procedure execution.

Module instance is an important concept for understanding the situation when the client/server infobase variant is used. Module instance contains the module's compiled code, values of global variables etc. Module instances for all the shared modules are created both on the server side and on the client side. Module instances of such objects as documents or catalog items are tied to their objects and can appear both on the server side and on the client side depending on where the object is created.

Shared modules comprise a shared library of procedures and functions that can be used in all the other modules.

Suppose that a module of some object, e.g. of document named D, contains a call to procedure P() defined in a shared module. The P() procedure is not enclosed in any preprocessor directives. In this case the P() procedure will be contained both in the server-side and in the client-side shared module instances. Thus, the module of the client side document will call the P() procedure from the client side shared module, and the module of the server side document will call the P() procedure from the server side shared module.
Now let's suppose that the P() procedure is enclosed in a #If Server Then ... #EndIf block. In this case, the client side shared module instance will not contain the P() procedure. All the calls to the P() procedure will be resolved in the server side shared module instance. That is, each P() call will always be processed on the server side.

Now let's suppose that the P() procedure is enclosed in a #If Client Then ... #EndIf block. In this case, the server side shared module instance will not contain the P() procedure. The calls to the P() procedure will only be possible on the client side. The module containing a call to the P() procedure cannot be instantiated on the server side, because the calls to client procedures from server are not supported, and the call to P() procedure from the server side will remain unresolved.

In the file-based mode the situation is much simpler : the client and the server sides are merged. In this case, Server, ThinClient, ThickClientManagedApplication and ThickClientOrdinaryApplication are defined. The code fragments enclosed in #If Server Then … #EndIf and #If ThickClientOrdinaryApplication Then … #EndIf blocks will not be excluded during the module compilation.

File server mode

In the file-based mode both #If Server Then ... #EndIf and #If Client Then ... #EndIf preprocessor instructions are skipped. Therefore an instance of code will always be available.

COM connection session

The following preprocessor instruction is used to enable procedure and function usage in external connection session:

#If ExternalConnection Then

#EndIf

Thin client

The following preprocessor instruction is used to enable procedure and function usage in thin client session:

#If ThinClient Then

#EndIf

Web client

The following preprocessor instruction is used to enable procedure and function usage in Web client session:

#If WebClient Then

#EndIf

1C:Enterprise Developer's Community