KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Using parenthesis to manage complex pointer dereferencing
PRODUCT: 4D | VERSION: 2004 | PLATFORM: Mac & Win
Published On: July 6, 2007
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

You can use parenthesis to control the way in which pointers are dereferenced in 4D or, more importantly, the order in which they are dereferenced.

The example in this Tech Tip illustrates this with the following:

-An array of pointers named ptr1
-An array of pointers named ptr2
-A Text array named $sample

Each element in ptr2 points to an element in ptr1. Each element in ptr1 points to an element in $sample. In order to dereference an element in ptr2 and, eventually, reach one of the elements in $sample the following syntax is used:

( (arrayptr{index}) -> )->

Used in an example:

ARRAY POINTER(ptr1;5)
ARRAY POINTER(ptr2;5)
ARRAY TEXT($sample;5)

For ($i;1;5)
   $sample{$i}:="test "+String($i)
   ptr1{$i}:=->$sample{$i}
   ptr2{$i}:=->ptr1{$i}
   ALERT((ptr2{$i}->)->)
End for



The Alert display will be the value of each element in the $sample Text array.

Related Sources:

Dereferencing pointer to an array vs. array of pointer