KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to retrieve the field names of a given table?
PRODUCT: 4D | VERSION: | PLATFORM: Mac & Win
Published On: April 8, 2004

Compatibility: Version 6.8.x and 2003.x

Here is a quick way to retrieve the field names of a given table. The method will expect a table name as a parameter and pass the field names of that table into an array. It will then return a pointer to that array.

Method: GetFieldNames
Parameter: Table Name
Returns: Pointer to the array of field names

C_TEXT($TableName;$1)
C_LONGINT($fieldNumber;$TableNb;$vlTable;$i)
C_POINTER($0)
C_BOOLEAN($done)

$TableName:=$1

$done:=False
$vlTable:=0
Repeat
  $vlTable:=$vlTable+1
  If (Table name($vlTable)=$TableName)
    $TableNb:=$vlTable
    $done:=True
  End if
Until (($done) | ($vlTable>=Count tables))

If ($done)
  $fieldNumber:=Count fields($TableNb)

  ARRAY TEXT(asFields;$fieldNumber)
  ARRAY LONGINT($FieldTypes;$fieldNumber)

  `Create an array of field names
  For ($i;1;$fieldNumber)
    asFields{$i}:=Field name($TableNb;$i)
  End for
Else
  ARRAY TEXT(asFields;0)
End if

$0:=->asFields