Form VL_SAM102: Visual Component Coding Techniques

LANSA

Form VL_SAM102: Visual Component Coding Techniques
Name: VL_SAM102

Description: The following RDMLX form is used to demonstrate the advantages and disadvantages of various RDMLX coding techniques.
FUNCTION OPTIONS(*DIRECT);
BEGIN_COM FORMPOSITION(ScreenCenter) HEIGHT(251) WIDTH(402);
DEFINE_COM CLASS(#PRIM_GPBX) NAME(#GPBX_1) DISPLAYPOSITION(1) HEIGHT(201) LEFT(8) PARENT(#COM_OWNER) TABPOSITION(1) TABSTOP(False) TOP(8) WIDTH(185);
;
DEFINE_COM CLASS(#STD_NUM.Visual) NAME(#VAR_1) CAPTION('Variable 1') DISPLAYPOSITION(4) LABELTYPE(Caption) LEFT(24) MARGINLEFT(60) PARENT(#GPBX_1) TABPOSITION(4) TOP(32) WIDTH(129);
;
DEFINE_COM CLASS(#STD_NUM.Visual) NAME(#VAR_2) CAPTION('Variable 2') DISPLAYPOSITION(3) LABELTYPE(Caption) LEFT(24) MARGINLEFT(60) PARENT(#GPBX_1) TABPOSITION(3) TOP(72) WIDTH(129);
;
DEFINE_COM CLASS(#STD_NUM.Visual) NAME(#VAR_3) CAPTION('Variable 3') DISPLAYPOSITION(2) LABELTYPE(Caption) LEFT(24) MARGINLEFT(60) PARENT(#GPBX_1) TABPOSITION(2) TOP(112) WIDTH(129);
;
DEFINE_COM CLASS(#STD_NUM.Visual) NAME(#VAR_4) CAPTION('Variable 4') DISPLAYPOSITION(1) LABELTYPE(Caption) LEFT(24) MARGINLEFT(60) PARENT(#GPBX_1) TABPOSITION(1) TOP(152) WIDTH(129);
DEFINE_COM CLASS(#STD_NUM) NAME(#VAR_4NONV);
;
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#BTN_1) CAPTION('Loop Method 1') DISPLAYPOSITION(5) LEFT(224) PARENT(#COM_OWNER) TABPOSITION(5) TOP(22) WIDTH(145);
;
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#BTN_2) CAPTION('Loop Method 2') DISPLAYPOSITION(4) LEFT(224) PARENT(#COM_OWNER) TABPOSITION(4) TOP(60) WIDTH(145);
;
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#BTN_3) CAPTION('Loop Method 3') DISPLAYPOSITION(3) LEFT(224) PARENT(#COM_OWNER) TABPOSITION(3) TOP(98) WIDTH(145);
;
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#BTN_4) CAPTION('Loop Method 4') DISPLAYPOSITION(2) LEFT(224) PARENT(#COM_OWNER) TABPOSITION(2) TOP(136) WIDTH(145);
;
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#BTN_CLEAR) CAPTION('Clear all Variables') DISPLAYPOSITION(6) LEFT(224) PARENT(#COM_OWNER) TABPOSITION(6) TOP(176) WIDTH(145);
;
Define #LoopLimit RefFld(#Std_Num) Length(*RefFld *Minus 1) Default(2000);
Define #LoopWork RefFld(#Std_Num);
;
;
* This routine uses a visual component (named #Var_1) as a loop variable.;
* The variables contents are changed every time the loop is executed,;
* but the changed value is not shown until the loop completes execution;
* and the event routine terminates, allowing the screen format to be;
* be repainted. This type of coding should be avoided where possible;
* because it incurs a performance overhead in continually updating;
* the visual component but gains no visual benefit from doing so.;
*;
* Conclusion : Using variables that have a visual context in situations of;
* frequent change (where NO visual advantage is gained or;
* required) incurs a possibly avoidable performance overhead.;
;
;
EVTROUTINE HANDLING(#BTN_1.Click);
Begin_Loop from(1) to(#LoopLimit) Using(#Var_1);
End_Loop ;
ENDROUTINE ;
;
* This routine uses a work field (named #LoopWork) that is not defined in a;
* visual context and at completion simply updates the result field (#Var_2);
* just once with the result. This is a recommended coding technique and it;
* performs better in this problem scenario than any of the other loops.;
;
* Conclusion : Using simple fields (ie: not defined as components) in situations;
* of frequent change mimimizes performance overheads.;
;
;
EVTROUTINE HANDLING(#BTN_2.Click);
Begin_Loop from(1) to(#LoopLimit) Using(#LoopWork);
End_Loop ;
Change #Var_2 #LoopWork;
ENDROUTINE ;
;
* This routine is similar to the #Btn_1 loop in that it uses it uses a visual;
* variable (#Var_3) as the loop variable, thus incurring a performance penalty;
* in updating the value in a visual context every time it is changed. However,;
* by using the UpdateDisplay method it gains a significant visual advantage;
* over the #Btn_1 routine by showing the changed values on the display every;
* time it is changed.;
;
* Conclusion : Using variables that have a visual context in situations of;
* frequent change (where a visual advantage is gained or;
* required) is a useful coding technique, but you must understand;
* the technqiues for and ramifications of doing this.;
;
;
EVTROUTINE HANDLING(#BTN_3.Click);
Begin_Loop from(1) to(#LoopLimit) Using(#Var_3);
Invoke #Var_3.UpdateDisplay;
End_Loop ;
ENDROUTINE ;
;
* This routine is similar to the #Btn_2 loop in that it uses a temporary;
* or work variable (#Var_4NonV) as the loop variable and maps its value;
* into the visual context (ie: #Var_4) just once at the termination of the loop.;
;
* The difference between this routine and the #Btn_2 routine is that #Var_4NonV;
* is defined as a component (in a NON VISUAL CONTEXT) where as the variable;
* #LoopWork (used by the #Btn_2 routine) is defined as a simple field.;
;
* Conclusion : Using non visual components (ie: not defined in a visual context);
* in situations of frequent change reduces performance overheads,;
* (but not as much as using a simple field does).;
;
;
EVTROUTINE HANDLING(#BTN_4.Click);
Begin_Loop from(1) to(#LoopLimit) Using(#Var_4NonV);
End_Loop ;
Change #Var_4 #Var_4NonV;
ENDROUTINE ;
;
* This routine simply clears all field and component values;
;
EVTROUTINE HANDLING(#BTN_CLEAR.Click);
Change (#Var_1 #Var_2 #Var_3 #Var_4) *Null;
ENDROUTINE ;
;
END_COM ;