4D v16.3

DEFAULT TABLE

Home

 
4D v16.3
DEFAULT TABLE

DEFAULT TABLE 


 

DEFAULT TABLE ( aTable ) 
Parameter Type   Description
aTable  Table in Table to set as the default

Tip: Although using DEFAULT TABLE and omitting the table name may make the code easier to read, many programmers find that using this command actually causes more problems and confusion than it is worth. In particular, note that DEFAULT TABLE takes priority when you use, for example, the DIALOG command with a project form and there is a default table form with the same name.

DEFAULT TABLE sets aTable as the default table for the current process.

There is no default table for a process until the DEFAULT TABLE command is executed. After a default table has been set, any command that omits the table parameter will operate on the default table. For example, consider this command:

 FORM SET INPUT([Table];"form")

If the default table is first set to [Table], the same command could be written this way:

 FORM SET INPUT("form")

One reason for setting the default table is to create code that is not table specific. Doing this allows the same code to operate on different tables. You can also use pointers to tables to write code that is not table specific. For more information about this technique, see the description of the Table name command.

DEFAULT TABLE does not allow the omission of table names when referring to fields. For example:

 [My Table]My Field:="A string" ` Good

could not be written as:

 DEFAULT TABLE([My Table])
 My Field:="A string" ` WRONG

because a default table had been set. However, you can omit the table name when referring to fields in the table method, form, and objects that belong to the table.

In 4D, all tables are “open” and ready for use. DEFAULT TABLE does not open a table, set a current table, or prepare the table for input or output. DEFAULT TABLE is simply a programming convenience to reduce the amount of typing and make the code easier to read.

Example  

The following example first shows code without the DEFAULT TABLE command. It then shows the same code, with DEFAULT TABLE. The code is a loop commonly used to add new records to a database. The FORM SET INPUT and ADD RECORD commands both require a table as the first parameter:

 FORM SET INPUT([Customers];"Add Recs")
 Repeat
    ADD RECORD([Customers])
 Until(OK=0)

Specifying the default table results in this code:

 DEFAULT TABLE([Customers])
 FORM SET INPUT("Add Recs")
 Repeat
    ADD RECORD
 Until(OK=0)



See also 

Current default table
NO DEFAULT TABLE

 
PROPERTIES 

Product: 4D
Theme: Table
Number: 46

This command can be run in preemptive processes

 
HISTORY 

Created: < 4D v6

 
ARTICLE USAGE

4D Language Reference ( 4D v16)
4D Language Reference ( 4D v16.1)
4D Language Reference ( 4D v16.2)
4D Language Reference ( 4D v16.3)