KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Deriving a table name from a field pointer
PRODUCT: 4D | VERSION: | PLATFORM: Mac & Win
Published On: July 31, 2002

Compatibility: 6.7.x and 6.8.x

When a pointer to a field is passed as a parameter, it is frequently desirable, or necessary, to have a pointer to the table to which the field belongs.

The following commonly used code reduces the need to pass a table pointer as a separate parameter.

Though the code in this routine is very short, it has been implemented in a separate routine named Shell_PointerToTableForField in order to be reused. Reuse, even of such small amounts of code, prevents errors (such as typos), and eliminates the need for retesting the code each time it is written.

Here is the 4D ORDER BY command using Shell_PointerToTableForField to return a pointer to a table:

ORDER BY(Shell_PointerToTableForField ($pFieldToOrderBy)->;$ pFieldToOrderBy ->;>)

Here is the code of Shell_PointerToTableForField:
If (False)
`Shell_PointerToTableForField
`$pTable:=Shell_PointerToTableForField (Field pointer)

`PURPOSE:
`When passed a field pointer, returns a pointer to the fieldĖ‡s table.

`PARAMETERS:
`$1 Field pointer
`$0 Table pointer for field pointer passed in $1
End if

C_POINTER($1;$0)

$0:=Table(Table($1))