Skip to main content
Version: Next

Methods

A method is basically a piece of code that executes one or several action(s). A method is composed of statements.

A statement performs an action, and may be simple or complex. Each statement usually consists of one line in the method (if necessary, it can however be split using the \ character).

The maximum size of a method is limited to 2 GB of text or 32,000 lines of code.

Method Types

In the 4D Language, there are several categories of methods. The category depends on how they can be called:

TypeCalling contextAccepts parametersDescription
Project methodOn demand, when the project method name is called (see Calling project methods)YesCan contain any code to execute any custom actions. Once a project method is created, it becomes part of the language of the project.
Object (widget) methodAutomatic, when an event involves the object to which the method is attachedNoProperty of a form object (also called widget)
Form methodAutomatic, when an event involves the form to which the method is attachedNoProperty of a form. You can use a form method to manage data and objects, but it is generally simpler and more efficient to use an object method for these purposes.
Trigger (aka Table method)Automatic, each time that you manipulate the records of a table (Add, Delete and Modify)NoProperty of a table. Triggers are methods that can prevent "illegal" operations with the records of your database.
Database methodAutomatic, when a working session event occursYes (predefined)There are 16 database methods in 4D.
ClassAutomatically called when an object of the class is instanciated or when a function of the class is executed on an object instance in any other methods or in a database field.yes (class functions)A Class is used to declare and configure the class constructor, properties, and functions of objects. See Classes