KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Retrieving a pointer to a variable or field using a name
PRODUCT: 4D | VERSION: 2003.1 | PLATFORM: Mac & Win
Published On: September 24, 2003

Version 6.7.x, 6.8.x and 2003.x

Here is a project method that will return a pointer to a variable and field.

  ` Utility Method: tool_Getpointer
  ` Return a pointer to a variable or field

C_POINTER($0)
C_STRING(255;$1)
C_STRING(255;$var)
C_LONGINT($tableID;$fieldID)
C_LONGINT($vlTable;$vlField;$i)
C_STRING(255;$tableName;0)
C_LONGINT($oci_l_tableMax)

$var:=$1
$tableID:=0
$fieldID:=0
$0:=Get pointer($var)
If (Undefined($0->))  ` assume that this is a field
  $oci_l_tableMax:=Count tables
  For ($vlTable;1;$oci_l_tableMax)
    $tableName:="["+Table name($vlTable)+"]"
    If (Position($tableName;$var)>0)
      $tableID:=$vlTable
      $vlTable:=$oci_l_tableMax+1
    End if
  End for

$var:=Replace string($var;$tableName;"")

  If ($tableID>0)
    $vlField:=Count fields($tableID)
    For ($i;1;$vlField)
      If (Field name($tableID;$i)=$var)
        $fieldID:=$i
        $i:=$vlField+1
      End if
    End for
  End if

  If (($tableID>0) & ($fieldID>0))
    $0:=Field($tableID;$fieldID)
  End if
End if

Example Usage:

C_POINTER(pointerVar)

pointerVar:=tool_Getpointer("myvariable") or pointerVar:=tool_Getpointer("[table]fieldname")