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.
You can pass process and interprocess, process or local arrays as parameters.
Here are some examples.
If((0<atNames)&(atNames<Size of array(atNames))
atNames:=atNames+1
End if
If you need to do the same thing for 50 different arrays in various forms, you can avoid writing the same thing 50 times, by using the following project method:
C_POINTER($1)
If((0<$1->)&($1-><Size of array($1->))
$1->:=$1->+1
End if
Then, you can write:
SELECT NEXT ELEMENT(->atNames)
SELECT NEXT ELEMENT(->asZipCodes)
SELECT NEXT ELEMENT(->alRecordIDs)
- The following project method returns the sum of all the elements of a numeric array (Integer, Long Integer, or real):
C_REAL($0)
$0:=0
For($vlElem;1;Size of array($1->))
$0:=$0+$1->{$vlElem}
End for
Note: Since 4D v13, you can just use the Sum function to calculate the sum of the elements of a number array.
Then, you can write:
$vlSum:=Array sum(->arSalaries)
$vlSum:=Array sum(->aiDefectCounts)
$vlSum:=Array sum(->alPopulations)
- The following project method capitalizes of all the elements of a string or text array:
For($vlElem;1;Size of array($1->))
If($1->{$vlElem}#"")
$1->{$vlElem}:=Uppercase($1->{$vlElem}[[1]])+Lowercase(Substring($1->{$vlElem};2))
End if
End for
Then, you can write:
CAPITALIZE ARRAY(->atSubjects)
CAPITALIZE ARRAY(->asLastNames)
The combination of arrays, pointers, and looping structures, such as ARRAY TO LIST, allows you to write many useful small project methods for handling arrays.