KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Acquiring distinct attribute paths in a 4D Object
PRODUCT: 4D | VERSION: 15.x, 16 | PLATFORM: Mac & Win
Published On: February 23, 2017

The command DISTINCT ATTRIBUTE PATHS finds all the attribute paths in the selected record of an object field type into an array. Similar to this command for 4D Objects is the following method where it scans a single object:

// --------------------------------------------------------------------------------
// Name: GET_4DOBJECT_ATTRIBUTE_PATHS
// Description: Method will in a 4D object to get the attribute paths in an array.
// Similar to the DISINCT ATTRIBUTE PATHS for an object field.
// Input:
// $1 (OBJECT) - 4D Object to search
// $2 (POINTER) - Pointer to an array of attribute paths listed
// --------------------------------------------------------------------------------
C_OBJECT($1;$objInput)
C_POINTER($2;$ptrArr)
C_TEXT($3;$objNameArrObj)
C_LONGINT($i;$j)
ARRAY TEXT($arrName;0)
ARRAY TEXT($arrNameTemp;0)
ARRAY LONGINT($arrNameType;0)

If (Count parameters<=3)
    $objInput:=$1
    $ptrArr:=$2
   
    If (Count parameters=3)
     $objNameArrObj:=$3
    End If
   
    OB GET PROPERTY NAMES($objInput;$arrName;$arrNameType)
   
    For ($i;1;size of array($arrName))
     Case of
      : (($arrNameType{$i}=Is text) | ($arrNameType{$i}=Is real) | ($arrNameType{$i}=Is Boolean))
   
       If ($objNameArrObj#"")
         APPEND TO ARRAY($ptrArr->;$objNameArrObj+$arrName{$i})
       Else
         APPEND TO ARRAY($ptrArr->;$arrName{$i})
       End If
      : ($arrNameType{$i}=Object array)
       APPEND TO ARRAY($ptrArr->;$arrName{$i})
       APPEND TO ARRAY($ptrArr->;$arrName{$i}+"[]")
       ARRAY OBJECT($refs;0)
       OB GET ARRAY($objInput;$arrName{$i};$refs)
   
       For($j;1;size of array($refs))
        GET_4DOBJECT_ATTRIBUTE_PATHS
($refs{$j};$ptrArr;$arrName{$i}+"[].")
       End For
   
      :($arrNameType{$i}=is object)
       APPEND TO ARRAY($ptrArr->;$arrName{$i})
        GET_4DOBJECT_ATTRIBUTE_PATHS (OB GET($objInput;$arrName{$i});$ptrArr;$arrName{$i}+".")
       End case
     End For

     // Clear duplicates
     For ($i;1;size of array($ptrArr->))
       $pos:=Find in array($ptrArr->;$ptrArr->{$i};$i+1)
             
       If ($pos<0)
         APPEND TO ARRAY($arrNameTemp;$ptrArr->{$i})
       End If

     End For

     CLEAR VARIABLE($ptrArr->)
     COPY ARRAY($arrNameTemp;$ptrArr->)
End If


Here are some examples with the same command:
C_OBJECT($obj)
ARRAY TEXT(attrPathArr;0)

// Each example will be loaded in $obj
GET_4DOBJECT_ATTRIBUTE_PATHS ($obj;->attrPathArr)

Example #1: Properties with array



Result:



Example #2: Properties with more array values



Result:



Example #3: Properties with object



Result: