Tech Tip: Form Methods and Form Events
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: July 22, 2025
When creating a form method, it is important to consider the form event that is enabled and to execute code based on the event that triggers the form method. A common approach is to check which form event was triggered and execute code using a Case ... End Case structure. Some events, such as On Mouse Move, can be triggered constantly, while others, like On Form Load, are triggered less frequently or only once.
Code that isn't place in a conditional will get trigger for every event. For example if the following code that should be use to initialize a variable applied to a date entry object on a form was improperly written as:
While the above code will work, it will trigger everytime a form event is triggered, while will seem to reset any changes to the date entry back to the current date.
Instead the code should be placed in an On Load form event, which is triggered when the form is opened and loading up:
This concept also applies to Form Objects which can also have their own method and events.
Code that isn't place in a conditional will get trigger for every event. For example if the following code that should be use to initialize a variable applied to a date entry object on a form was improperly written as:
// SomeFormMethod var dateFormObjVar : Date dateFormObjVar:=Current Date |
While the above code will work, it will trigger everytime a form event is triggered, while will seem to reset any changes to the date entry back to the current date.
Instead the code should be placed in an On Load form event, which is triggered when the form is opened and loading up:
// SomeFormMethod Case of :(Form event code=On Load) var dateFormObjVar : Date dateFormObjVar:=Current Date End Case |
This concept also applies to Form Objects which can also have their own method and events.