KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Calling the Current default table command from a component
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: June 15, 2018

As discussed in the design reference documentation for Interaction between components and host databases, a component database will have acess to the tables of the host database. As noted, the following commands can be called from within a component:

DEFAULT TABLE
NO DEFAULT TABLE
Current default table

Just as with a host database, the command Current default table, when called in the component database, will return a nil pointer if no default table is set, even if the default table is set in the host database!

This may seem confusing, but it is important to keep in mind the context of the calls and remember that when commands are called from a component they are executed in the context of the component (except for the EXECUTE METHOD command that uses the context of the method specified by the command).

If the default table is set in the host database, then within the host database calls to Current default table will return a pointer to that table. This is because the context of the default table in the host database is set. A call to Current default table then from a method in the component will return a nil pointer because of the context of the call. See the below image which illustrates this point.



To call the DEFAULT TABLE command, since the table cannot be referenced directly in the component, a pointer to the table can be passed in with a simple method:

C_LONGINT($1)
$tablepointer:=Table($1)
DEFAULT TABLE($tablepointer->)

After calling a command like the above from within a component method, that component would then return a pointer to the default table when calling the Current default table command.



Link to design reference documentation documentation.