During the development phase, early detection of syntax errors is important for producing quality code. Real-time code checking is a valuable aid to developers. Not only does it improve efficiency, it also enhances quality and boosts productivity. By correcting errors immediately, you can concentrate on the functional development of your application, rather than on annoying bugs that crop up during compilation.
With 4D 20 R8, we’re delighted to introduce two new features that will transform the way you work.
- The first is the ability to associate a class with a form, enabling syntax checking with expressions such as Form.myProperty.
- The second is a real-time check of expressions in the property list, with a description of the error or warning displayed.
Associating a class with a form
You can now associate a user class with a form using the new “Form class” attribute. This attribute allows you to type the object returned by the Form command, permitting the use of expressions like Form.myProperty. The user class can be from the host project or a component.
Automatic Instantiation at Runtime
When opening a form, you can pass an object to the DIALOG command. This object then becomes accessible within the form via the Form command.
The object passed to the DIALOG command can be an instance of a class. Here’s how you can do it:
var $h : Integer
var $o : cs.Person
$o:=cs.Person.new()
$h:=Open form window("FormWithClass")
DIALOG("FormWithClass"; $o)
Starting from version 4D 20 R8, if you define the “Form class” property in the form without passing an object to the DIALOG command, 4D automatically handles the instantiation. Simply write:
var $h : Integer
$h:=Open form window("FormWithClass")
DIALOG("FormWithClass")
The Form command returns an object that is an instance of the “Person” class. You can check this in the form with the OB Instance of command.
$n:=OB Instance of(Form; cs.Person)
Now, you can call a class function simply by writing: “Form.message()”.
Benefits for the code editor
Auto-completion feature
The Form command benefits from auto-completion in the code editor. By typing “Form.”, 4D will suggest all the properties and functions declared in the associated class. No more inverting two letters in a property name or using a lowercase letter instead of a capital letter in a function name.
For instance, with our simple “Person” class defined as follows:
property firstname : Text
property lastname : Text
property email : Text
Class constructor
This.firstname:=""
This.lastname:=""
This.email:=""
Function get fullname() : Text
return This.firstname+" "+This.lastname
When utilizing the Form command within a form method, the code editor offers you an accurate list to complete your code:
Check syntax feature
When you use expressions of the “Form.myProperty” type in the form method, or in the methods of form objects, you’ll benefit from the power of the syntax checker.
Let’s take the example of the previous class. In the code of the form method, we:
- force an integer into a text attribute,
- use an unknown attribute,
- assign an integer to a computed attribute of text type.
In the following image, you can see that the code editor has effectively identified errors or warnings.
Benefits for the form editor
Syntax checking integrated into the property list
Syntax checking is no longer limited to the code editor. This functionality is extended to expressions in the property list (such as “Datasource” or “Meta info expression“). As a result, you’ll receive immediate notifications of errors and warnings.
No need to wait for compilation results to discover errors. Thanks to this feature, you’ll be informed as early as the editing phase.
Compilation
Of course, if you haven’t resolved the new errors directly, the compiler will still catch them during the compilation process.
Compiler dialog
All warnings and errors will be displayed in the compilation window. If you double-click on a form object expression, the corresponding form will open, highlighting the problematic object and its property in the property list.
Compile project command
In case of compilation failure, the Compile project command returns an object with warnings and errors. The command has also been extended to return warnings or errors detected in the form object expressions.
{ "success":false, "errors":[{ "message":"Undeclared property 'firstName' used. (550.26)", "isError":false, "code":{ "type":"formObjectExpression", "formName":"Person", "objectName":"InputFirstname", "propertyName":"dataSource", "file":"[object File]" } }] }
What’s next
These new features will make writing code easier and more efficient.
Don’t hesitate to share your experiences with these improvements. Your comments are invaluable in helping us to understand how these tools help you on a daily basis, and to better adapt them to your needs.