KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Retrieving a pointer to a table by its name
PRODUCT: 4D | VERSION: | PLATFORM: Mac & Win
Published On: April 22, 2004

Compatibility: Version 6.8.x and 2003.x

Sometimes it may be useful to retrieve a pointer to a table instead of explicitly naming one. For example, it might be more useful to be able to dynamically retrieve a pointer to a table called "MyTable" instead of using it directly as [MyTable].

This method gets that pointer for you. All you need to pass in is the name of a table and it will either return the pointer to the table or Nil if the table does not exist. This can be useful if you need to reference a table from a list of table names stored as strings.

C_POINTER($0)
C_TEXT($1)

C_LONGINT($i)
ARRAY TEXT($tables;0)
C_POINTER($pTable)

For ($i;1;Count tables)
  APPEND TO ARRAY($tables;Table name($i))
End for

If (Find in array($tables;$1)#-1)

  $pTable:=Table(Find in array($tables;$1))

End if

$0:=$pTable