Sending Sets


ACI - Documentation Français English German ACI Technical Notes ACI Technical Notes, By Subject Back Previous Next Find

Sending Sets

By Jean-Yves Fock-Hoon

Quality Assurance Manager, 4D, Inc.

Technical Note 01-22

Technical Notes for Technical Notes for 01-05 May 2001

Abstract


Sending sets from one 4D Client to other clients is easer under version 6.7.x than in previous versions. This Tech Note shows how to send a set without creating a temporary document that is subsequently loaded by the clients that receive the set.

Introduction


This technical note shows how easy it is possible to send sets from one 4D Client to other 4D Clients in v6.7.

The idea is very simple.

The Idea


In previous versions of 4D (prior to 6.7), sets could be saved as documents. These documents were copied onto other 4D Client machines that would load them.

4D Version 6.0.x

4D 6.0.x added some new features such as Blob commands, the Execute on Server command, and the GET PROCESS VARIABLE command.

These commands allowed us to send sets from 4D Client to 4D Server automatically. The behavior is essentially the same in all cases:

4D Client saves the set into a document and loads this document into a blob variable.

The blob could be sent to the Server using either the GET PROCESS VARIABLE or SET PROCESS VARIABLE commands, executing a process on the Server or with the Execute on Server command.

Each 4D Client would run a separate process that would check if there is a new set and would load the variable.

Once the variable has been loaded, it would be resaved into a 4D Set document, ready to be loaded.

4D Version 6.5.x

4D 6.5.x received some new features such as REGISTER CLIENT and EXECUTE ON CLIENT commands:

The method did not really change. REGISTER CLIENT and EXECUTE ON SERVER allowed you to define which 4D Client needed to update sets.

The problem remained. You still needed to save the set, load it into a Blob, resave the Blob as a document, and reload the document.

4D Version 6.7.x

4D 6.7.x received some new features such as the CREATE SET FROM ARRAY and BOOLEAN ARRAY FROM SET commands:

These two commands are more useful. They can save you time by eliminating the need to create these temporary documents.

You have just to convert the sets into arrays. Since arrays cannot be passed as parameters, you still need to put them into Blob variables and use them when executing the Execute on Server or EXECUTE ON CLIENT commands.

These variables will be received as parameters in the process created on the specified 4D Client. You only need to recreate these arrays from the Blob variables and create a new set from this array and Voila! Managing temporary filenames and creating useless files have been avoided.

Using the Example Database

Launch the Set database (v1.1) with 4D Server and connect with different 4D Clients.

From the Custom menus, select the item "How does it work?". This will display a window with different records.

Highlight some records and create three sets, SetF, SetG, and SetH by clicking on the three buttons on the right side of the window.

In this example, we will try to send these three sets to other 4D Clients.

From this dialog, allowing other 4D Clients to update your sets is active. You can deactivate it by selecting "Disallow updates from others" from the "4D Server" menu.

This item will just turn off a Boolean variable that will be tested to see if the sets can be updated. Reselect the item to enable the automatic updates.

From this menu, you can select "Update all 4D Clients". This will execute the following method MODSEL_AskUpdateClient:

If (<>Is4DClient)
   ARRAY BOOLEAN(A_SetF;0)
   ARRAY BOOLEAN(A_SetG;0)
   ARRAY BOOLEAN(A_SetH;0)

C_BLOB(BlobF;BlobG;BlobH)

   BOOLEAN ARRAY FROM SET(A_SetF;"SetF")
   BOOLEAN ARRAY FROM SET(A_SetG;"SetG")
   BOOLEAN ARRAY FROM SET(A_SetH;"SetH")
  
   VARIABLE TO BLOB(A_SetF;BlobF)
   VARIABLE TO BLOB(A_SetG;BlobG)
   VARIABLE TO BLOB(A_SetH;BlobH)

   If (True)
       `No need to get the registered clients if we want to do it for all 4D Clients
    
      EXECUTE ON CLIENT("@";"SERVER_Update_Client_Requested";BlobF;Blobg;BlobH)

      Else 
      ` If this operation is required for a specific 4D Client

      GET REGISTERED CLIENTS(AClientList;AMethods)
      For ($i;1;Size of array(AClientList))
         EXECUTE ON CLIENT(AClientList{$i};"SERVER_Update_Client_Requested";BlobF;Blobg;BlobH)
      End for 
   End if 
End if 

First of all, we will create arrays from these sets. The size of an array will depend on the size of a set, which equals to the number of records in the set, divided by 8. Boolean arrays and sets use the same scheme, one bit per element and are very cheap in memory. The first record of the set will match with the first element of the array, which will be element 0. If the value is True, this means that the record is member of the set. However, the number of elements could be different than the number of records into the selection.

Sets work per bits. One byte is required to define 5 records. The three unused bits will be set to False. Creating a Boolean array from a set will also have the same behavior. The three last unused elements will remain set to False.

Once the arrays have been created, you only need to store them in Blob variables that will be sent as parameters to other 4D Clients.

If you want to send this to all 4D Clients, you can provide "@" as the 4D Client's name. Otherwise, you could get the registered 4D Clients, pick up which ones that need to be updated and make a loop on them to execute the EXECUTE ON CLIENT command.

Each 4D Client will check on the Server to see if any method needs to be executed. By default, it will be checked every two seconds. It's up to you to change this value when executing the REGISTER CLIENT command. When the application sees that the SERVER_Update_Client_Requested method needs to be executed, a process will be created on the Client side and will execute this method:

ARRAY BOOLEAN(A_SetF;0)
ARRAY BOOLEAN(A_SetG;0)
ARRAY BOOLEAN(A_SetH;0)

C_BLOB(BlobF;BlobG;BlobH;$1;$2;$3)
BlobF:=$1
BlobG:=$2
BlobH:=$3

BLOB TO VARIABLE(BlobF;A_SetF)
BLOB TO VARIABLE(BlobG;A_SetG)
BLOB TO VARIABLE(BlobH;A_SetH)

CREATE SET FROM ARRAY([People];A_SetF;"<>SetF")
CREATE SET FROM ARRAY([People];A_SetG;"<>SetG")
CREATE SET FROM ARRAY([People];A_SetH;"<>SetH")

CALL PROCESS(<>CurProcNum)

Blob variables will be retrieved as parameters and the three arrays will be created from them. From these arrays, we can create these sets. In this example, we choose to create inter-process sets and call the main process to manage this new up-coming. In the form method of our window, we will check each Outside call events and check if sets can be updated. If yes, these will be updated; intermediate sets will be recomputed and the window will be redrawn to display the new contents of these sets.

See Also


More about these commands:

REGISTER CLIENT: http://www.acius.com/ACIDOC/CMU/CMU00648.HTM

EXECUTE ON CLIENT: http://www.acius.com/ACIDOC/CMU/CMU00651.HTM

BOOLEAN ARRAY FROM SET: http://www.acius.com/ACIDOC/CMU/CMU00646.HTM

CREATE SET FROM ARRAY: http://www.acius.com/ACIDOC/CMU/CMU00641.HTM


ACI - Documentation Français English German ACI Technical Notes ACI Technical Notes, By Subject Back Previous Next Find