It is important to know and understand 4D's technique of updating fields, variables, and widgets on a form.
Regardless of how many or how often fields, variables, and widgets are updated in value or location, the change is not reflected on a 4D form until the execution pointer exits the method being executed. Once the execution pointer returns to the 4D runtime, the last values and moves are applied to the form.
Subforms can now be used to create highly sophisticated forms. Subforms can be swapped in an out of a parent form, OBJECT SET SUBFORM, making the display of data tricky. To do it effectively requires several steps.
1) The new subform must be swapped in using OBJECT SET SUBFORM.
2) A trigger must be set to cause the execution pointer to return to a method set the values to be displayed on the form. SET TIMER and CALL PROCESS are two such trigger setters.
3) The execution pointer returned to 4D runtime.
4) The fields or variables of the subform populated.
5) The execution pointer returned to 4D runtime.
For a simple example which demonstrate how forms are updated in 4D, create a form similar to the one below with the code for the Form method, button objects, and one project method shown below.
Form method
If (False) // Name: TestForm_d End if //process_wide_variable_declarations C_LONGINT(Cnt_L) //local_variable_declarations C_LONGINT($Ndx;$FormEvt_L) $FormEvt_L:=Form event Case of : ($FormEvt_L=On Close Box) CANCEL //-------------------------------------------------------------------------- : ($FormEvt_L=On Load) MyVar:=Current time Cnt_L:=5 // //-------------------------------------------------------------------------- : ($FormEvt_L=On Clicked) MyVar:=Current time // //-------------------------------------------------------------------------- : ($FormEvt_L=On Timer) MyVar:=Current time Cnt_L:=Cnt_L-1 If (Cnt_L=0) SET TIMER(0) End if // //-------------------------------------------------------------------------- : ($FormEvt_L=On Outside Call) MyVar:=Current time // //-------------------------------------------------------------------------- End case |
When running the code in Button 1 the form will only reflect the time following the last pass through the For loop. When running Buttons 2 and 3 the form will be updated with each pass through the loop, that is because control is returned to 4D after each call to the form method.
Object method: Button 1
If (False) // Name: TestForm_d.Button1 End if C_LONGINT($Ndx) For ($Ndx;1;5) MyVar:=Current time DELAY PROCESS(Current process;60) End for |
Object method: Button 2
If (False) // Name: TestForm_d.Button2 End if SET TIMER(60) |
Object method: Button 3
If (False) // Name: TestForm_d.Button3 End if __TestingMethod |
Project method: __TestingMethod
If (SHELL_SelfStart ($MethodName_T;$MethodName_T)) For ($Ndx;1;5) CALL PROCESS(1) DELAY PROCESS(Current process;60) End for End if |