The new method attribute "Execute on Server" was introduced in 4D v11 SQL Release 2. When this option is checked, the project method is always executed on the server, regardless of how the method is called.
Execution Context: The execution context of the project method is the same as that of triggers: the method on the server shares the same database context for locking records and for transactions as the corresponding context on the client-side.
All the parameters of the method ($1, $2, etc.) are sent to the server and the value of parameter $0, if used, is returned to the client. Unlike the 4D Execute on server command, this option does not create a process on the server. 4D Server uses the "twin" process of the client process that requested the execution.
Moreover, this option simplifies the principle of delegating the execution of a method on the server since the transfer of parameters is automatically carried out in both directions, as with a "normal" method call. The Execute on server command functions asynchronously and therefore requires more programming and makes use of semaphores for reading the results; in contrast this method executes synchronously within the server's "twin" process and thus the client "waits" for the called method to complete and return the execution pointer to the client-side.
Pointers: If you pass a pointer to a variable (simple variable, array or array element), the pointed value is also sent to the server. If the pointed value is modified on the server by the method, the modified value is returned to the client in order to update the corresponding variable on the client side.
Pointers to a table or field are sent as references (table number, field number). The current record value is not automatically exchanged.
C_POINTER:($1:)`Pointer to table C_POINTER:($2:) `Pointer to field C_POINTER:($3:) `Pointer to array C_TEXT:($4:) `Value to be searched for C_LONGINT:($0:) `Result `Search and send back values for each record QUERY($1->;$2->=$4) While(Not(End selection($1->))) APPEND TO ARRAY($3->;myFormula($1)) NEXT RECORD($1->) End while UNLOAD RECORD($1->) $0:=Records in selection($1->) |
NOTE: in the above example, $3 is a pointer to an array on the client-side. The method, executed on the server-side in the client "twin" process, added elements to the array and transparently transferred the new array elements back to the client.