Tech Tip: A simpler way to manage method parameters of the same type using curly brackets
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: October 16, 2017
If a method is created with multiple parameters of the same type, a short cut of accessing the parameter data is to use the curly brackets as shown below:
C_LONGINT($params) C_POINTER(${$params}) |
One useful case is when creating a QUERY / QUERY SELECTION based on the number of parameters entered. Here is a sample code based on the number of parameters where the code can be redundant as more parameters are entered:
C_TEXT($1;$searchStr) C_POINTER($2;$3;$4;$5) $searchStr:=$1 Case of : (Count parameters=3) QUERY($2->;$3->="@"+$searchStr+"@") : (Count parameters=4) QUERY($2->;$3->="@"+$searchStr+"@";*) QUERY($2->; | ;$4->="@"+$searchStr+"@") : (Count parameters=5) QUERY($2->;$3->="@"+$searchStr+"@";*) QUERY($2->; | ;$4->="@"+$searchStr+"@";*) QUERY($2->; | ;$5->="@"+$searchStr+"@") Else End case |
The following code below is rewritten to use the curly brackets:
C_LONGINT($i;$params) C_TEXT($1;$searchStr) C_POINTER(${$params}) $searchStr:=$1 QUERY($2->;$3->="@"+$searchStr+"@";*) For ($i;3;Count parameters;1) QUERY($2->;|;${$i}->="@"+$searchStr+"@";*) End for QUERY($2->) |
The curly brackets can be used with other data types like longint and text but it should be checked if the parameters being passed are of mixed types. The example above anticipated that the first parameter was a type text but the rest was going to be a pointer