Have you ever wondered about 4D’s autocompletion feature or asked yourself why 4D suggests all functions used in the code? Since an object is a very generic type, 4D only knows what it’s really storing at runtime. However, that doesn’t help much when you’re writing your code.
4D now offers a new, alternative syntax which will greatly enhance autocompletion when declaring your variables.
The new syntax is very simple and consists of the “var” keyword, the name of the variable, and its type.
var <variableName> : <type>
You can declare variables with both the classic and the new syntaxes in the same database.
For data types
This syntax can be used to define variable data types. The following are some examples showing the correspondence between both syntaxes for variables of text, numeric, and image data types.
var $text1; $text2 : Text
var $num : Integer
var $pict : Picture
For user classes
Until now, all instances of a class were declared as an object. Now with the new syntax, you can define which class instance your object belongs to using the cs command and the name of your class. This gives you access to the functions and attributes of the class.
var $person : cs.Person
For 4D classes
Objects such as File or Folder are objects belonging to internal 4D classes. You can access them with the 4D command.
$folder:=Folder(Current resource folder)
var $folder : 4D.Folder
$folder:=Folder(Current resources folder)
What about ORDA?
In a previous blog post, we showed you that you can override the ORDA classes (Dataclass, Entity, and Entity selection) with your own classes. You can also use this new syntax to enjoy autocompletion.
var $dataclass : cs.Company
var $entity : cs.CompanyEntity
var $entitySelection : cs.CompanySelection