home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / developmen / longlist / STRLIST.OPL < prev    next >
Text File  |  1994-04-13  |  5KB  |  160 lines

  1. /* 
  2.     Example OPL program which replaces choice list in a dialog
  3.     with a VASTR array allowing more choice items than the normal
  4.     list (limited to 254 items - this example creates a choice
  5.     list with 360 items).
  6.  
  7.     A related OPL program FIXLIST.OPL uses the VAFIX class of
  8.     array to speed up the choice list with a penalty of
  9.     increased memory use.
  10.  
  11.     This file should be accompanied by VARRAY.TXT which describes
  12.     some of the concepts used here in a little more detail.
  13.  
  14. */
  15.  
  16. #define DatDialogPtr        $36
  17.  
  18. #define E_GEN_NOMEMORY        -10
  19.  
  20. #define SE_CHLIST_NSEL        1
  21. #define SE_CHLIST_DATA        2
  22. #define SE_CHLIST_RETAIN    4
  23.  
  24. #define C_VASTR            6
  25.  
  26. #define O_VA_INIT        17
  27. #define O_VA_APPEND        7
  28.  
  29. #define O_WN_SET        10
  30.  
  31.  
  32. /*  MAIN: is our top level procedure  */
  33.  
  34. PROC main:
  35.  
  36.     GLOBAL        ret%                              /*  General return  */
  37.  
  38.     ret% = Choice%:    
  39.  
  40.     IF ret% < 0
  41.         PRINT "Error was", ret%
  42.     ELSE
  43.         PRINT "You chose item", ret%
  44.     ENDIF
  45.     GET
  46.  
  47. ENDP
  48.  
  49.  
  50. /*  CHOICE%: replaces the choice list and displays the dialog  */
  51.  
  52. PROC Choice%:
  53.  
  54.     GLOBAL        datdlg%                      /*  DatDialogPtr static  */
  55.     GLOBAL        vastr%                        /*  The C_VASTR object  */
  56.     GLOBAL        set%(3)                      /*  SE_CHLIST structure  */
  57.     GLOBAL        pset%                          /*  Pointer to set%()  */
  58.  
  59.     LOCAL        choice%                /*  Live variable for dCHOICE  */
  60.     LOCAL        lgnsel%              /*  set.nsel in SE_CHLIST 'set'  */
  61.     LOCAL        index%                  /*  Index of the choice list  */
  62.  
  63.     index%  = 1                             /*  Index of the dialog item  */
  64.     pset%   = ADDR(set%())          /*  pset% points to SE_CHLIST struct  */
  65.  
  66.     lgnsel%  = 0                         /*  set.nsel in SE_CHLIST 'set'  */
  67.  
  68.     set%(1)  = (SE_CHLIST_DATA) OR (SE_CHLIST_NSEL) OR (SE_CHLIST_RETAIN)
  69.     set%(3)  = lgnsel%
  70.     
  71.     PRINT "Generating list, wait a short time"
  72.     ret% = Array%:
  73.     IF ret% < 0
  74.         RETURN ret%
  75.     ENDIF
  76.  
  77.     dINIT "Test dialog"                              /*  Init the dialog  */
  78.     dCHOICE choice%, "Date", "dummy"       /*  Create a choice list with
  79.                                                                a dummy entry  */
  80.  
  81.     datdlg%  = PEEKW(DatDialogPtr)  /*  datdlg% points to current dialog  */
  82.     set%(2)  = vastr%                              /*  set.data = varray  */
  83.     
  84.     ret% = ENTERSEND0(datdlg%, O_WN_SET, #index%, #pset%)
  85.  
  86. /*  WN_SET is a method provided by the DLGBOX class and is used to
  87.     set the data element in the property of the control associated
  88.     with the dialog box item.
  89. */
  90.     IF (ret% <> 0)                                  /*  Return any error  */
  91.         RETURN ret%
  92.     ENDIF
  93.  
  94.     IF (DIALOG > 0)                                   /*  Run the dialog  */
  95.         lgnsel% = choice%
  96.         RETURN lgnsel%                  /*  Return the option chosen  */
  97.     ENDIF
  98.  
  99. ENDP
  100.  
  101.  
  102. /*  ARRAY%: creates the array and fills it with example data  */
  103.  
  104. PROC Array%:
  105.  
  106.     LOCAL        yea%                                    /*  The year  */
  107.     LOCAL        mon%                                   /*  The month  */
  108.     LOCAL        buf$(10)                     /*  The built-up string  */
  109.     LOCAL        pbuf%                            /*  Pointer to buf$  */
  110.     LOCAL        gran%                    /*  Granularity for VA_INIT  */
  111.     LOCAL        ohand%               /*  Category handle of OLIB.DYL  */
  112.  
  113.     gran% = 16                                     /*  Granularity is 16  */
  114.     
  115.     ret% = FINDLIB(ohand%, "OLIB.DYL")  /*  Find category handle of OLIB  */
  116.     IF (ret% <> 0)
  117.         RETURN ret%                                 /*  Return error  */
  118.     ENDIF
  119.  
  120.     vastr% = NEWOBJH(ohand%, C_VASTR)  /*  Create an instance of C_VASTR  */
  121.      IF (vastr% = 0)
  122.         RETURN E_GEN_NOMEMORY                         /*  Return OOM  */
  123.     ELSE
  124.         ret% = ENTERSEND0(vastr%, O_VA_INIT, #gran%)  /*  Init array  */
  125.         IF (ret% <> 0)
  126.             RETURN ret%                     /*  Return any error  */
  127.         ENDIF
  128.     ENDIF
  129.  
  130.     yea% = 1970                                        /*  Start at 1970  */
  131.     mon% = 1                                        /*  Start at January  */
  132.  
  133. /*  
  134.     The following loops round and round adding all the month & year
  135.     combinations between Jan 1970 and Dec 2000. It is a convenient
  136.     way of generating a very long list. The strings are then added
  137.     to the array using VA_APPEND.
  138. */
  139.     WHILE (yea% <= 2000)
  140.         WHILE (mon% <= 12)
  141.             buf$ = MONTH$(mon%) + CHR$(32) + GEN$(yea%, 4) + CHR$(0)
  142.             pbuf% = UADD(ADDR(buf$), 1)         /*  Skip the LCB  */
  143.             ret% = ENTERSEND0(vastr%, O_VA_APPEND, #pbuf%)
  144.  
  145. /*
  146.     VA_APPEND is a method provided by the (abstract) class
  147.     VAROOT. It appends the records pointed to by, in this case 'pbuf%',
  148.     to the end of the array.
  149. */
  150.             IF (ret% <> 0)
  151.                 RETURN ret%             /*  Return any error  */
  152.             ENDIF
  153.             mon% = mon% + 1                 /*  Reset to January  */
  154.         ENDWH
  155.         yea% = yea% + 1                       /*  Increment the year  */
  156.               mon% = 1                             /*  Increment the month  */
  157.     ENDWH
  158.     RETURN 0                                                /*  No error  */
  159. ENDP
  160.