KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Object Methods Basics
PRODUCT: 4D | VERSION: | PLATFORM: Mac & Win
Published On: April 28, 2000

When defining an object method, it is a good idea to write your code so that it is conditional to the form event that is actually executed.

For example, if you select the On data change and On clicked events, your code should look like the following (provided you want to execute separate pieces of code for each event):



Even at the early stage of the creation of an object method you should carefully consider this architecture, even if it seems heavy-footed. Why? In a typical situation, you may need to go back to an object's definition to enable an additional event, without making sure that the existing code is compatible with the new event.

For example, let us assume that you create a button that calls a subroutine which saves the current record when the button is clicked. Then you enable the On clicked event and call that subroutine at the first level in the object method. If, a couple of weeks afterwards, you choose to disable that button when the form is loaded, select the On load event and add a call to another subroutine at the same level as the first subroutine, both subroutines will be executed for both events, with disastrous consequences.

If, on the other hand, you use the following architecture, you will never run into this type of problem: