Log In    |    Knowledge Base    |    4D Home
Tech Tip: Passing variables from 4D client to 4D Server
Published On: April 2, 1999

To update the value of a variable on the server from client, you need to know the process number of the process on server. This tech tip demonstrates one method of doing this.
This method involves starting a process on the server that will remain on the server for as long as the server is running. The server process number is stored in the interprocess variable <>server_process.

The server process is then paused. It's purpose is just exit, it does not need to perform any actions. So the code could be as simple as:

When a client connects, it needs to get the process number from the <>server_process variable, on the server. This is done by executing a new process on the server and using this server Process ID in the GET PROCESS VARIABLE command to assign the value of the <>server_process variable on the server to the <>server_process variable on the client.

The last line in the above method sets the vend variable to true allowing the process to execute out.

From this point on, the <>server_process variable can be used to transfer interprocess variables between the client and server machines. Interprocess variables are available to all process on the server including stored procedures and triggers
IMPORTANT: When using the VARIABLE TO VARIABLE, SET PROCESS VARIABLE and GET PROCESS VARIABLE commands it is best not to use local variables and to use compiler directives to define the variable types. Consult the Language reference manual for more details.<

Highlight and copy to your clipboard for pasting into 4D
 ` WARNING: It's best not to use local variables
  ` It's HIGHLY suggested that you define variable types everywhere you use them

  ` ---------------- execute in "on server startup" method ----------------

<>server_process:=New process("Server_Process";30*1024;"Server_Process")

  ` ---------------- "Server_Process" method ----------------

DELAY PROCESS(Current process;30)
Until (<>End_Server_Process)

  ` ---------------- execute on startup for client ----------------

vprocess_id:=Execute on server("Get_Server_Process_ID";32*1024;"Get_Server_Process_ID")

GET PROCESS VARIABLE(vprocess_id;<>server_process;<>server_process)
Until (<>server_process # 0)

SET PROCESS VARIABLE(vprocess_id;vend;vend)  ` end server process

  ` ---------------- "Get_Server_Process_ID" method ----------------


DELAY PROCESS(Current process;30)
Until (vend)