Tech Tip: Utility Method to Get Table Pointer From Table Name
PRODUCT: 4D | VERSION: 15.x | PLATFORM: Mac & Win
Published On: November 14, 2017
Below is a utility method that will return a table pointer of the passed table name:
// Method: util_getTablePointer // Description // Get the current server service status // // Return // $0 - Pointer to Table Name // ---------------------------------------------------- C_POINTER($0) C_TEXT($1) C_TEXT(name_t) C_LONGINT(tableNumber_l) If (Count parameters>0) name_t:=$1 Begin SQL SELECT TABLE_ID FROM _USER_TABLES WHERE TABLE_NAME=:name_t INTO :tableNumber_l; End SQL If (tableNumber_l>0) $0:=Table(tableNumber_l) Else $0:=Null End if End if |
Below are examples of using the method on a Database with only one table, "Table_1":
C_POINTER($pointer_p) C_TEXT($text_t) $text_t:="Table_1" $pointer_p:=util_getTablePointer($text_t) TRACE |
Since "Table_1" exists the results are a pointer to the table:
C_POINTER($pointer_p) C_TEXT($text_t) $text_t:="Table_2" $pointer_p:=util_getTablePointer($text_t) TRACE |
Since "Table_2" does not exist the results are Nil/Null: