The Code for a Mode Often Becomes an Event Routine

Visual LANSA

The Code for a Mode Often Becomes an Event Routine

What you would write an IF_MODE statement in a LANSA function often corresponds to what you write in an event routine in Visual LANSA. For instance, in a LANSA function you would normally delete an item by writing a DELETE statement in the IF_MODE statement testing for the *DELETE mode. In Visual LANSA you would put the DELETE statement in the Click event of the Delete button:

LANSA function

Visual LANSA form

 

IF_MODE IS(*DELETE)

     DELETE FROM_FILE(PSLMST) 

ENDIF

 

EVTROUTINE HANDLING(#DELETE.CLICK)

   DELETE FROM_FILE(PSLMST) WITH_KEY(#EMPNO) 

ENDROUTINE 

 

Just as the code in the in the IF statement only gets executed when the condition is true, the code in the Click event of the Delete button only gets executed when you click the button.

You will probably find that your programs become simpler when they are event driven because there will be fewer nested control structures as the code is broken down to event routines. Also, it is easy to follow a program when you can see straight away which component and event will cause which action.

In the simplest case, when you convert an existing LANSA function to a Visual LANSA form you can:

  • Create buttons that correspond to the modes used in the function, for example Add, Change and Delete buttons.
  • Copy the RDML from the IF_MODE statements to the Click events of the corresponding buttons.

Ý 6.9.2 What Is Different Between Event-Driven and Procedural Programs?