4D v13.4

Arrays and the 4D Language

Home

 
4D v13.4
Arrays and the 4D Language

Arrays and the 4D Language  


 

 

Arrays are 4D variables. Like any variable, an array has a scope and follows the rules of the 4D language, though with some unique differences.

You can create and work with local, process, and interprocess arrays. Examples:

 ARRAY INTEGER($aiCodes;100) ` Creates local array of 100 2-byte Integer values
 ARRAY INTEGER(aiCodes;100) ` Creates process array of 100 2-byte Integer values
 ARRAY INTEGER(◊aiCodes;100) ` Creates interprocess array of 100 2-byte Integer values

The scope of these arrays is identical to the scope of other local, process, and interprocess variables:

A local array is declared when the name of the array starts with a dollar sign ($).

The scope of a local array is the method in which it is created. The array is cleared when the method ends. Local arrays with the same name in two different methods can have different types, because they are actually two different variables with different scopes.

When you create a local array within a form method, within an object method, within or a project method called as subroutine by the two previous type of method, the array is created and cleared each time the form or object method is invoked. In other words, the array is created and cleared for each form event. Consequently, you cannot use local arrays in forms, neither for display nor printing.

As with local variables, it is a good idea to use local arrays whenever possible. In doing so, you tend to minimize the amount of memory necessary for running your application.

A process array is declared when the name of the array starts with a letter.

The scope of a process array is the process in which it is created. The array is cleared when the process ends or is aborted. A process array automatically has one instance created per process. Therefore, the array is of the same type throughout the processes. However, its contents are particular to each process.

An interprocess array is declared when the name of the array starts with <> (on Windows and Macintosh) or with the diamond sign, Option-Shift-V on a US keyboard (on Macintosh only).

The scope of an interprocess array consists of all processes during a working session. They should be used only to share data and transfer information between processes.

Tip: When you know in advance that an interprocess array will be accessed by several processes that could possible conflict, protect the access to that array with a semaphore. For more information, see the example for the Semaphore command.

Note: You can use process and interprocess arrays in forms to create form objects such as scrollable areas, drop-down lists, and so on.

You can pass an array as parameter to a 4D command or to the routine of a 4D Plug-in. On the other hand, you cannot pass an array as parameter to a user method. The alternative is to pass a pointer to the array as parameter to the method. For details, see the section Arrays and Pointers.

Unlike text or string variables, you cannot assign one array to another. To copy (assign) an array to another one, use COPY ARRAY.

 
PROPERTIES 

Product: 4D
Theme: Arrays

 
SEE ALSO 

Arrays
Arrays and Pointers