# Event-Handler Routines

Load on Demand |

Load on Demand is an event specific to list boxes (i.e. Standard, Formatted, List View and Report View) that can be used to trigger an event-handler routine to load a large number of items into a list box in a more efficient manner. In many cases, a list box is loaded in a routine that loads the entire contents of the list box, either one item at a time, or all the items concatenated together. Either way, if the list is large, this can be quite time-consuming (especially when using WindX). However, if the number of elements to be loaded into the list box is known, then the list box can be loaded on demand, or as needed, thus reducing time and overhead.

To take advantage of the Load on Demand feature, you must create two event-handler routines. The first is an initialization routine that can be associated with a Post Display event. In it, you must set the 'ItemCount property of the list box to the number of items to be loaded. The second routine must be associated with the Load on Demand event for the list box. This routine contains the load-on-demand logic which will be triggered by a CTL event generated by NOMADS. In this routine, the application obtains the index number of the items needed for the list box by reading the new 'ItemNeededFrom and 'ItemNeededTo properties. It then loads the list box with the contents of the specified items by setting 'Item and 'ItemText$. The application will only read and display those items that the user actually scrolls into view. If there are no elements required, 'ItemNeededFrom and 'ItemNeededTo will be zero.

NOMADS reserves a CTL value between 23001 - 23999 for Load on Demand events. See Load on Demand.

#### Note:
Load on Demand is not available for Tree View list boxes.

## Defining Load on Demand

To set on-demand loading for a list box, click the Load on Demand check box on the Attributes tab (using the Folder Style version of the NOMADS Panel Designer), then select the associated Logic button to invoke the Load on Demand Logic dialogue. Enter the program/entry point that will be performed, called or executed when a load-on-demand signal occurs.

Example:

The following example loads a list box using on-demand loading:

> SET_LISTBOX_COUNT: \
> ! Initialization logic
> X=HFN;
> OPEN INPUT (X,ISZ=512,ERR=*NEXT)"CSTFILE";
> READ RECORD (X,ERR=*RETURN)R$;
> CLOSE (X)
> LB1.CTL'ITEMCOUNT=DEC(R$(15,4));
> TOTAL_ITEMS=LB1.CTL'ITEMCOUNT
> CST_FN=HFN;
> OPEN (CST_FN,IOL=*)"cstfile"
> I=1
> RETURN
> !
> LOAD_BY_DEMAND: \
> ! Load-on-demand logic
> NEEDED_TO=LB1.CTL'ITEMNEEDEDTO;
> NEEDED_FROM=LB1.CTL'ITEMNEEDEDFROM
> IF NEEDED_FROM=0 OR NEEDED_TO=0 \
> THEN RETURN
> FOR I=NEEDED_FROM TO NEEDED_TO
> READ (CST_FN,RNO=I,DOM=*NEXT)
> IF CST_AMT<0 \
> THEN CLR$=EVS("'red'") \
> ELSE CLR$=""
> LB1.CTL'ITEM=I;
> LB1.CTL'ITEMTEXT$=CST_ID$+"/"+CST_NAME$+"/"+ \
> CLR$+STR(CST_AMT:"-$###,##0.00")+"/"
> NEXT
> RETURN

#### Note:
RNO= usage may cause performance degradation with large files.