* first define protocol constants as above
 
TICK = chr(251)          && #define TICK chr(251)
 
sel_reps()
 
* This is a loader function, a modified version of pick to
* include a call to achoice's user defined function, and the
* achoice user function itself
 
FUNCTION sel_reps
 
PRIVATE save_scr, ret_val, save_sel, num_recs, i, func_name
PRIVATE t, l, b, r, reenter, start_sel, rel_start, dummy
 
    save_sel = select()
    SELECT 0
    USE reports
 
    * declare and load arrays
    num_recs = reccount()
    PRIVATE reps[num_recs], funcs[num_recs]
 
    FOR i = 1 TO num_recs
 
        reps[i] = " " + reports -> desc
        funcs[i] = reports -> fname
 
        SKIP
 
    NEXT
 
    t = 10
    l = 10
    b = 22
    r = 60
 
    * This is the start of our pick routine with a call to user func
    save_scr = savescreen(t, l, b, r)
    scroll(t, l, b - 1, r - 1, 0)
 
    * set color to white on black for shadow
    set_attr(7, b, l + 1, b, r)
    set_attr(7, t + 1, r, b, r)
 
    @ t, l TO b - 1, r - 1
 
    reenter = .T.
    rel_start = 0
    start_sel = 1
 
    * NOTE our reentry condition inside this loop...
    DO WHILE reenter
        start_sel = achoice(t + 1, l + 1, b - 2, r - 2, reps, .T., ;
                          "afunc", start_sel, rel_start)
        * If the last operation was a toggle, reenter so change
        * can be seen
        reenter = lastkey() = ENTER
 
    ENDDO
 
    * now run the functions associated with the selected reports
    FOR i = 1 TO num_recs
 
        IF substr(reps[i], 1, 1) == TICK
            func_name = funcs[i] + "()"
            dummy = &func_name
        ENDIF
 
    NEXT
 
    SELECT (save_sel)
    restscreen(t, l, b, r, save_scr)
 
RETURN ret_val
 
FUNCTION afunc
 
PARAM mode, cur_elem, rel_pos
PRIVATE key
 
    * save rel pos in case we reenter
    rel_start = rel_pos
    DO CASE
        CASE mode = AC_EXCEP
            key = lastkey()
 
            DO CASE
                CASE key = ESC
                    ret_val = AC_ABORT
 
                CASE key = ENTER
                    * flip first character
                    IF substr(reps[cur_elem], 1, 1) == TICK
                     reps[cur_elem] = " " + substr(reps[cur_elem], 2)
                    ELSE
                     reps[cur_elem] = TICK + substr(reps[cur_elem], 2)
                    ENDIF
 
                    * NOTE - must be SELECT here
                    ret_val = AC_SELECT
 
                OTHERWISE
                    ret_val = AC_CONTINUE
            ENDCASE
 
        OTHERWISE
            ret_val = AC_CONTINUE
    ENDCASE
 
RETURN ret_val

