Re: 4GL Q: Popup window from within Construct statement
Posted in 1993
>manmetha@gauss.rutgers.edu (Rajesh Malhotra) writes: >> A question on the construct statement in 4GL. >> I am creating the where clause of a select using construct, >>but when the cursor goes to a particular field, I want to throw up >>a window and let the user select one of the available values. How >>would I do this from within construct? >> From within INPUT ARRAY, I can do this using the ON KEY and >>the INFIELD() function, figure out which field the cursor is on, and >>throw up a Window and let the user pick one value from a list. >> Is it possible to achieve the same functionality from within >>a construct statement? >As someone else responded, you SHOULD be able to do it the same with >version 4.1 of 4GL, but you will probably run into bug #14985 >the following should work: > ON KEY (...) > CASE > WHEN INFIELD(somefield) > # call a function to pick a value > LET disptxt = do_pick("D") > # put that value in the field > DISPLAY disptxt TO screen_record.somefield > ... > END CASE >What happens is, as page S-88 of the 4GL 4.1 SUPPLEMENT tells us, on an >ON KEY clause, the current input buffer is saved and restored for the >current screen field after the clause is executed. Apparently, the bug >addresses the problem that there seems to be no way to overwrite the >saved buffer, as the DISPLAY statement above should. I just stummbled >across this myself yesterday, so I'll try a coupld workarounds I have >in mind and post if I find anything. As promised, here's an ineligent, but rather straightforward and relatively short workaround: # EXAMPLE OF code to work around error #14985 # Implement a pick function in a CONSTRUCT statement # in this example, we are doing a CONSTRUCT on three columns # (col1-col3), and allow pick screens for two of them (col1 & col2) # define a large variable as usual for the where clause DEFINE mclause CHAR(1000) # create a record to hold contents of each field buffer # remember that the field buffer can be larger than the field itself DEFINE f_fldbuf RECORD col1 CHAR(80), col2 CHAR(80), col3 CHAR(80) END RECORD # define flags that tell if we went into the pick function # 1 for each column we can pick from DEFINE p_col1 SMALLINT DEFINE p_col2 SMALLINT INITIALIZE f_fldbuf.* TO NULL # Set any beginning defaults LET f_fldbuf.col1 = ... # set all pick flags to false LET p_col1 = FALSE LET p_col2 = FALSE # start a loop in case we use the pick functions WHILE TRUE CONSTRUCT mclause ON stat.col1, stat.col2, stat.col3 FROM s_qry.* BEFORE CONSTRUCT # display any defaults DISPLAY f_fldbuf.col1 TO s_qry.col1 DISPLAY f_fldbuf.col2 TO s_qry.col2 DISPLAY f_fldbuf.col3 TO s_qry.col3 IF p_col1 THEN # we are looping around from picking col1, # so go back to that field LET p_col1 = FALSE NEXT FIELD col1 END IF IF p_col2 THEN # we are looping around from picking col2, # so go back to that field LET p_col2 = FALSE NEXT FIELD col2 END IF ON KEY (...) # use the pick utility CASE WHEN INFIELD(col1) # can the pick function for col1 LET f_fldbuf.col1 = pick_function("col1") # bug #14985 prevents us from just DISPLAYING the # resultant pick to the field and continuing. We have to # loop back through the construct. IF LENGTH(f_fldbuf.col1) > 0 THEN LET p_col1 = TRUE EXIT CONSTRUCT END IF WHEN INFIELD(col2) # can the pick function for col2 LET f_fldbuf.col2 = pick_function("col2") IF LENGTH(f_fldbuf.col2) > 0 THEN LET p_col2 = TRUE EXIT CONSTRUCT END IF END CASE # fill in the contents of the field buffer for every single # column in the CONSTRUCT, so we don't lose them when/if we loop # back through the construct. AFTER FIELD col1 LET f_fldbuf.col1 = get_fldbuf(col1) AFTER FIELD col2 LET f_fldbuf.col2 = get_fldbuf(col2) AFTER FIELD col3 LET f_fldbuf.col3 = get_fldbuf(col3) END CONSTRUCT # if we exited the construct via running the pick function, # loop back up through the CONSTRUCT again. See the # BEFORE CONSTRUCT control block for more details IF NOT int_flag AND (p_col1 OR p_col2) THEN # back through construct another time CONTINUE WHILE END IF EXIT WHILE END WHILE IF int_flag THEN LET int_flag = FALSE ... RETURN END IF # and so on Send email or post any questions ================ Dennis J. Pimple Informix CSE / Denver