Skip to main content
Version: 20 R7 BETA

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:

EventObject MethodsForm MethodWhich Objects
On LoadYesYesAll objects
On UnloadYesYesAll objects
On ValidateYesYesAll objects
On ClickedYesYesInvolved object only
On Double ClickedYesYesInvolved object only
On Before KeystrokeYesYesInvolved object only
On After KeystrokeYesYesInvolved object only
On After EditYesYesInvolved object only
On Getting FocusYesYesInvolved object only
On Losing FocusYesYesInvolved object only
On ActivateNeverYesNone
On DeactivateNeverYesNone
On Outside CallNeverYesNone
On Page ChangeNeverYesNone
On Begin Drag OverYesYesInvolved object only
On DropYesYesInvolved object only
On Drag OverYesNeverInvolved object only
On Mouse EnterYesYesAll objects
On Mouse MoveYesYesAll objects
On Mouse LeaveYesYesAll objects
On Mouse UpYesNeverInvolved object only
On Menu SelectedNeverYesNone
On Bound variable changeNeverYesNone
On Data ChangeYesYesInvolved object only
On Plug in AreaYesYesInvolved object only
On HeaderYesYesAll objects
On Printing DetailYesYesAll objects
On Printing BreakYesYesAll objects
On Printing FooterYesYesAll objects
On Close BoxNeverYesNone
On Display DetailYesYesAll objects
On Open DetailYes (List box)YesNone except List boxes
On Close DetailYes (List box)YesNone except List boxes
On ResizeNeverYesNone
On Selection ChangeYesYesInvolved object only
On Load RecordNeverYesNone
On TimerNeverYesNone
On ScrollYesNeverInvolved object only
On Before Data EntryYes (List box)NeverInvolved object only
On Column MovedYes (List box)NeverInvolved object only
On Row MovedYes (List box)NeverInvolved object only
On Column ResizeYes (List box and 4D View Pro Area)NeverInvolved object only
On Header ClickYes (List box and 4D View Pro Area)NeverInvolved object only
On Footer ClickYes (List box)NeverInvolved object only
On After SortYes (List box)NeverInvolved object only
On Long ClickYes (Button)YesInvolved object only
On Alternative ClickYes (Button and List box)NeverInvolved object only
On ExpandYes (Hier. list and list box)NeverInvolved object only
On CollapseYes (Hier. list and list box)NeverInvolved object only
On Delete ActionYes (Hier. list and list box)NeverInvolved object only
On URL Resource LoadingYes (Web Area)NeverInvolved object only
On Begin URL LoadingYes (Web Area)NeverInvolved object only
On URL Loading ErrorYes (Web Area)NeverInvolved object only
On URL FilteringYes (Web Area)NeverInvolved object only
On End URL LoadingYes (Web Area)NeverInvolved object only
On Open External LinkYes (Web Area)NeverInvolved object only
On Window Opening DeniedYes (Web Area)NeverInvolved object only
On VP Range ChangedYes (4D View Pro Area)NeverInvolved object only
On VP ReadyYes (4D View Pro Area)NeverInvolved object only
On Row ResizeYes (4D View Pro 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.