Skip to main content
Version: Next

REGISTER CLIENT

History
ReleaseChanges
21* parameter ignored
11.3period parameter ignored

REGISTER CLIENT ( clientName )

ParameterTypeDescription
clientNameTextName of the 4D client session

Description

The REGISTER CLIENT command “registers” a 4D client station with the name specified in clientName on 4D Server, so as to allow other clients or possibly 4D Server (by using stored methods) to execute methods on it by using the EXECUTE ON CLIENT command. Once it is registered, a 4D client can then execute one or more methods for other clients.

Notes:

  • You can also automatically register each client station that connects to 4D Server by using the “Register Clients at Startup...” option in the Properties dialog box.
  • If this command is used with 4D in local mode, it has no effect.
  • More than one 4D client station can have the same registered name.

When this command is executed, a process, named clientName, is created on the client station. This process can only be aborted by the UNREGISTER CLIENT command.

Once the command is executed, it is not possible to modify a 4D client’s name on the fly. To do so, you must call the UNREGISTER CLIENT command, then the REGISTER CLIENT command.

Example

In the following example, we are going to create a small messaging system that allows the client workstations to communicate between themselves.

  1. This method, Registration, allows you to register a 4D client and to keep it ready to receive a message from another 4D client:
  //You must unregister before registering under another name
var vPseudoName : Text
 UNREGISTER CLIENT
 Repeat
    vPseudoName:=Request("Enter your name:";"User";"OK";"Cancel")
 Until((OK=0)|(vPseudoName#""))
 If(OK=0)
    ... // Don’t do anything
 Else
    REGISTER CLIENT(vPseudoName)
 End if
  1. The following instruction allows you to get a list of the registered clients. It can be placed in the :
var PrClientList : Integer
 PrClientList:=New process("4D Client List";32000;"List of registered clients")
  1. The method 4D Client List allows you to recuperate all the registered 4D clients and those that can receive messages:
var $Ref; $p : Integer
ARRAY TEXT($ClientList;0)
ARRAY LONGINT($ListeCharge;0)

 If(Application type=4D Remote Mode)
  // the code below is only valid in client-server mode
    $Ref:=Open window(100;100;300;400;-(Palette window+Has window title);"List of registered clients")
    Repeat
       GET REGISTERED CLIENTS($ClientList;$ListeCharge)
  //Retrieve the registered clients in $ClientList
       ERASE WINDOW($Ref)
       GOTO XY(0;0)
       For($p;1;Size of array($ClientList))
          MESSAGE($ClientList{$p}+Char(Carriage return))
       End for
  //Display each second
       DELAY PROCESS(Current process;60)
    Until(False) // Infinite loop
 End if
  1. The following method allows you to send a message to another registered 4D client. It calls the Display_Message method (see below).
var $Addressee; $Message : Text
 $Addressee:=Request("Addressee of the message:";"")
  // Enter the name of the people visible in the window generated by the
  // On Startup database method
 If(OK#0)
    $Message:=Request("Message:") // message
    If(OK#0)
       EXECUTE ON CLIENT($Addressee;"Display_Message";$Message) // Send message
    End if
 End if
  1. Here is the Display_Message method:
 #DECLARE($message : Text)
 ALERT($message)
  1. Finally, this method allows a client station to no longer be visible by the other 4D clients and to no longer receive messages:
 UNREGISTER CLIENT

System variables and sets

If the 4D client is correctly registered, the OK system variable is equal to 1. If the 4D client was already registered, the command doesn’t do anything and OK is equal to 0.

See also

EXECUTE ON CLIENT
GET REGISTERED CLIENTS
UNREGISTER CLIENT

Properties

Command number648
Thread safe
Modifies variablesOK