KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Declare Variables as Table Classes for Better Autocomplete Suggestions
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: April 25, 2022

One of the nice features of the 4D Method editor is the autocomplete suggestions when typing out items and hitting the Tab key. When a table is entered and then the next item should be a field, hitting Tab will list the fields for the table.

For example, with the following table:


Typing out:

[Table_1]

Then hitting tab will show:

This is also applicable to ORDA with object notation:


However, if an undeclared variable or object variable is assigned an entity selection, hitting tab will not list the fields. In the following example, the autocomplete only suggests "all" and does not list anything else:


Instead, declaring the variable as an entity class of the table will allow the method editor to pull the attributes and functions of the class:


As shown, in the first line, the declaration of $myEntSel as a Table_1Selection class instead of an Object allows the method editor to make suggestions based on the class instead of a generic object. This can help with writting code by allowing the fields of the specified table to be listed. This can also alleviate issues caused by incorrect character cases, as object notation is case-sensitive.