Skip to main content
Version: 21

Form Events

Form events are events that can lead to the execution of the form method and/or form object method(s). Form events allow you to control the flow of your application and to write code that is executed only when a specific event occurs.

In your code, you control the events using the FORM Event command, that returns the triggered event. For example:

//code of a button
If(FORM Event.code=On Clicked)
// do something when the button is clicked
End if

Every form and every active object on the form can listen to a predefined set of events, but only the events that you enabled at the form level and/or at every object level will actually occur.

Event object

Each event is returned as an object by the FORM Event command. By default, it contains the following properties:

PropertyTypeDescription
objectNametextName of the object triggering the event - Not included if the event is triggered by the form
codelongintNumeric value of the form event. Also returned by the Form event code command
descriptiontextName of the form event (e.g. "On After Edit")

Additional properties are returned when the event occurs on specific objects. In particular:

Events and Methods

When a form event occurs, 4D performs the following actions:

  • First, it browses the objects of the form and calls the object method for any object (involved in the event) whose corresponding object event property has been selected.
  • Second, it calls the form method if the corresponding form event property has been selected.

Do not assume that the object methods, if any, will be called in a particular order. The rule of thumb is that the object methods are always called before the form method. If an object is a subform, the object methods of the subform’s list form are called, then the form method of the list form is called. 4D then continues to call the object methods of the parent form. In other words, when an object is a subform, 4D uses the same rule of thumb for the object and form methods within the subform object.

Except for the On Load and On Unload events (see below), if the form event property is not selected for a given event, this does not prevent calls to object methods for the objects whose same event property is selected. In other words, enabling or disabling an event at the form level has no effect on the object event properties.

The number of objects involved in an event depends on the nature of the event.

Call Table

The following table summarizes how object and form methods are called for each event type:

EventCodeObject MethodsForm MethodWhich Objects
On Activate11NeverYesNone
On After Edit45YesYesInvolved object only
On After Keystroke28YesYesInvolved object only
On After Sort30Yes (List box)NeverInvolved object only
On Alternative Click38Yes (Button and List box)NeverInvolved object only
On Before Data Entry41Yes (List box)NeverInvolved object only
On Before Keystroke17YesYesInvolved object only
On Begin Drag Over46YesYesInvolved object only
On Begin URL Loading47Yes (Web Area)NeverInvolved object only
On Bound variable change54NeverYesNone
On Clicked4YesYesInvolved object only
On Close Box22NeverYesNone
On Close Detail26Yes (List box)YesNone except List boxes
On Collapse44Yes (Hier. list and list box)NeverInvolved object only
On Column Moved32Yes (List box)NeverInvolved object only
On Column Resize33Yes (List box and 4D View Pro Area)NeverInvolved object only
On Data Change20YesYesInvolved object only
On Deactivate12NeverYesNone
On Delete Action58Yes (Hier. list and list box)NeverInvolved object only
On Display Detail8YesYesAll objects
On Double Clicked13YesYesInvolved object only
On Drag Over21YesNeverInvolved object only
On Drop16YesYesInvolved object only
On End URL Loading49Yes (Web Area)NeverInvolved object only
On Expand43Yes (Hier. list and list box)NeverInvolved object only
On Footer Click57Yes (List box)NeverInvolved object only
On Getting Focus15YesYesInvolved object only
On Header5YesYesAll objects
On Header Click42Yes (List box and 4D View Pro Area)NeverInvolved object only
On Load1YesYesAll objects
On Load Record40NeverYesNone
On Long Click39Yes (Button)YesInvolved object only
On Losing Focus14YesYesInvolved object only
On Menu Selected18NeverYesNone
On Mouse Enter35YesYesAll objects
On Mouse Leave36YesYesAll objects
On Mouse Move37YesYesAll objects
On Mouse Up2YesNeverInvolved object only
On Open Detail25Yes (List box)YesNone except List boxes
On Open External Link52Yes (Web Area)NeverInvolved object only
On Outside Call10NeverYesNone
On Page Change56NeverYesNone
On Plug in Area19YesYesInvolved object only
On Printing Break6YesYesAll objects
On Printing Detail23YesYesAll objects
On Printing Footer7YesYesAll objects
On Resize29NeverYesNone
On Row Moved34Yes (List box)NeverInvolved object only
On Row Resize60Yes (4D View Pro Area)NeverInvolved object only
On Scroll59YesNeverInvolved object only
On Selection Change31YesYesInvolved object only
On Timer27NeverYesNone
On Unload24YesYesAll objects
On URL Filtering51Yes (Web Area)NeverInvolved object only
On URL Loading Error50Yes (Web Area)NeverInvolved object only
On URL Resource Loading48Yes (Web Area)NeverInvolved object only
On Validate3YesYesAll objects
On VP Range Changed61Yes (4D View Pro Area)NeverInvolved object only
On VP Ready9Yes (4D View Pro Area)NeverInvolved object only
On Window Opening Denied53Yes (Web Area)NeverInvolved object only

Always keep in mind that, for any event, the method of a form or an object is called if the corresponding event property is selected for the form or objects. The benefit of disabling events in the Design environment (using the Property List of the Form editor) is that you can reduce the number of calls to methods and therefore significantly optimize the execution speed of your forms.

WARNING: The On Load and On Unload events are generated for objects if they are enabled for both the objects and the form to which the objects belong. If the events are enabled for objects only, they will not occur; these two events must also be enabled at the form level.