4D v14

Events

Home

 
4D v14
Events

Events    


 

 

In addition to the manipulations explained in the video, you should also note that:

Not all objects have the same events: for example, you cannot check the "On Data Change" event for a button since you cannot "enter" its contents (title).

Here are a few examples:

  • On Mouse Enter
    When the mouse enters an object's “air space”.
  • On Data Change
    At the exit of a field or variable whose content changed.
    This is primarily used for checks on input, formatting (upper- and lowercase), queries, re-calculations.
  • On Clicked
    When an object is clicked (mainly buttons, popups, menus, etc.)
    Can also be used on enterable objects.
  • On Getting Focus
    The object just received focus (from On Clicked, used with the tab key or with programming).
  • On Load
    Just before a form is displayed on the screen or used to print.
    During this event initialization is usually performed.
  • On Printing Detail
    During record printing.
    Allows, for example, setting a value for total, concatenation variables.

This list helps you understand events. You can refer to the 4D documentation for a complete description of events.

There’s one important detail that new users always ask: “Do I need to check form events or object events?” The response is simple: everything depends on where you are going to create your method.
The form method, in theory, should only contain what is relevant to processing the entire form:

  • resizing
  • outside call
  • display/hiding objects
  • etc.

Whereas object methods should contain what is specific to an object itself (button, field, etc.). That's the general rule and you should have several good reasons before you consider breaking it.

Keep this in mind:

  • Form method: Centralized, global processing, easy to maintain.
    Risks being executed more often than needed.
  • Object method: Specific, adapted, executed only when necessary. It easily allows porting an object using copy-paste (especially if using pointers).
    Requires duplicating the method of calling the method in each object.

It does happen that we move certain processes into the form method.

For example, you must re-calculate a value depending on 10 enterable parameters. For each modified parameter, you must re-perform the calculation. Rather than put the formula (or method call) in each of the 10 parameter fields, it is possible to move this calculation into the form method.

In this case, it’s easier and centralized; however, it is highly likely that the re-calculation will be done more often than necessary - especially when modifying an area that doesn’t figure in the final calculation. (Note: 4D can let you know which object was modified so we can adapt the calculation according to this information).

It is important to know the order in which events are executed. For example, for a button, events are executed in the following order:

  • On Mouse Enter
  • On Mouse Move
  • On Getting Focus
  • On Clicked (if any)
  • On Mouse Leave
  • On Losing Focus

A field or a variable on which you click:

  • On Mouse Enter
  • On Mouse Move
  • On Getting Focus
  • On Data Change (if any)
  • On Losing Focus
  • On Mouse Leave

To save time when writing your code and to make it more reliable, remember to set up macros (“macros.xml” file).

For example, you can create a macro that writes the following code for you whenever you type “#$evt” in your method:

 $evt:=Form event
 Case of
    :($evt=On Data Change)
 
    :($evt=On Load)
 
 End case

While you are still learning to use 4D, we recommend that you start off by putting your methods in your objects; you’ll have more flexibility for updating. Then, start by using generic method calls and finally, when everything works properly, see what you can move from your object methods to your form method or project methods. Then you can start passing pointers as well.

To go further:
Take a good look at how events work because they will allow you to precisely understand exactly when to execute your programming. You'll also find a number of ideas for powerful first steps by using events such as:

  • On Drag Over
  • On Drop
  • On Selection Change
  • plus the three ’On Mouse’ events (Move, Leave, Enter)

and of course, the old standbys:

  • On Clicked
  • On Double Clicked
  • On Long Click
  • etc.

 
 

 
PROPERTIES 

Product: 4D
Theme: Events

 
ARTICLE USAGE

Self-training ( 4D v13)
Self-training ( 4D v14)