When a database has a lot of form objects to manage there are two coding paths to manage, Brute Force or Centralized Coding.
-- Brute Force is the simplest to understand and code but inefficient to maintain. When more than one form object does the same job and that job changes the code in each button has to be changed. The trap is remembering all the objects that will have to be updated and then spending the time necessary to update each.
-- Centralized Coding takes forethought but is the most efficient to maintain. In Centralized Coding each object calls a Project Method that executed the code for that object. The task is to segregate code in the method and execute the code for the calling object.
In earlier versions of 4D this could be challenging because 4D allowed multiple objects have the same name. Current versions of 4D enforce each object on a given form having a unique Object name. So objects on different forms with the same unique Object name can easily be managed from one Project Method.
For example the code below could be called from multiple forms from objects with the same Object name and preform the needed task. If a code update is needed is only has to be preformed in one method instead of in each object.
C_TEXT($Obj_Name_T;$1) $Obj_Name_T:=$1 Case of : ($Obj_Name_T="OBJ_Email_T") // ...validate email format : ($Obj_Name_T="OBJ_URL_T") // ...validate URL format : ($Obj_Name_T="OBJ_Phone_T") // ...validate phone number format Else ASSERT(False;"Unknown case test!") End case |
NOTE: Objects have two names, Object name and Variable name. Multiple objects on a form can have the same "Variable name" but each object has to have a unique "Object name."