WORDWRAP fields and INPUT ARRAY
Posted in 1994
Although it doesn't solve Liam's problem, which started the discussion, here's the example of how I handle the INPUT ARRAY/WORDWRAP problem. ============================================================ Dennis J. Pimple Informix Software Inc Senior Consultant Denver Colorado USA dennisp@informix.com Voice:303-850-0210 Fax:303-779-4025 ########### # INFORMIX PROFESSIONAL SERVICES ####### # ## Denver, Colorado ###### # ### ================================================== ##### # #### File: %M% SCCS: %I% %P% #### # ##### Program: EXAMPLE of using a long character variable ### # ###### in an INPUT ARRAY. ## # ####### Author: Dennis J. Pimple # ########### Date: %G% %U% # THE PROBLEM: you can't have a WORDWRAP field in a SCREEN ARRAY, # I suspect because of the way arrays and WORDWRAP fields are defined # in the perform screen (both use a matching field tag) # THE SOLUTION: Have a non-WORDWRAP field in the array, display part # of the string in that field, and as the user moves into that field, # pop a window and do INPUT BY NAME on an appropriately WORDWRAPPED # field. # This example was heavily edited from a working application to show only # the code pertinent to the problem. It won't compile without significant # editing. # Here's the screen file with the array: ----------------------- CUT HERE FOR stat.per ---------------------------------- DATABASE FORMONLY SCREEN { [f001 |f002|f003 |n ] { REPEAT AS REQUIRED ...} } ATTRIBUTES f001 = FORMONLY.sdate TYPE DATE, FORMAT = "mm/dd/yy"; f002 = FORMONLY.catid TYPE SMALLINT; f003 = FORMONLY.sdetl TYPE CHAR; n = FORMONLY.ne TYPE CHAR, NOENTRY; INSTRUCTIONS DELIMITERS " " SCREEN RECORD s_stat[20] (FORMONLY.sdate, FORMONLY.catid, FORMONLY.sdetl, FORMONLY.ne) END -------------------------------------------------------------------------------- # Here's the screen file with the WORDWRAP: ----------------------- CUT HERE FOR sdetl.per --------------------------------- DATABASE FORMONLY SCREEN { [f003 ] { REPEAT AS REQUIRED ...} } ATTRIBUTES f003 = FORMONLY.sdetl, WORDWRAP COMPRESS; "full Status description"; INSTRUCTIONS DELIMITERS " " END -------------------------------------------------------------------------------- # and the 4GL code: ----------------------- CUT HERE FOR stat.4gl ---------------------------------- # these are modular variables # assume other variables are local and defined appropriately DEFINE ma_stat ARRAY[60] OF RECORD # Input array sdate DATE, catid SMALLINT, sdetl CHAR(60), ne CHAR(3) # NOENTRY END RECORD # define a shadow array to hold the long string we edit in the popup. # See the BEFORE INSERT and AFTER DELETE control blocks that show how # it is kept up-to-date with ma_stat DEFINE ma_sdetl ARRAY[60] OF RECORD # hold entire detail record sdetl CHAR(####) END RECORD DEFINE sdetl_l SMALLINT # length ma_stat.sdetl DEFINE mstat_x SMALLINT # max array count DEFINE mstat_s SMALLINT # screen record size DEFINE mstat_t SMALLINT # tot array filled ... #---------------------------------------------------------------------# MAIN OPEN FORM stat FROM "stat" DISPLAY FORM stat ... CALL set_count(act) INPUT ARRAY ma_stat WITHOUT DEFAULTS FROM s_stat.* BEFORE ROW LET arr = arr_curr() LET scr = scr_line() LET act = arr_count() BEFORE INSERT # open up ma_sdetl IF arr <= act THEN FOR x = act TO arr STEP -1 IF x <= mstat_x THEN LET ma_sdetl[x+1].* = ma_sdetl[x].* END IF END FOR INITIALIZE ma_sdetl[arr].* TO NULL INITIALIZE ma_stat[arr].* TO NULL END IF AFTER DELETE # bring ma_sdetl up to date IF arr < act THEN FOR arr = arr+1 TO act LET ma_sdetl[arr-1].* = ma_sdetl[arr].* END FOR END IF INITIALIZE ma_stat[act].* TO NULL INITIALIZE ma_sdetl[act].* TO NULL BEFORE FIELD sdetl # call the function that does the WORDWRAP input, # telling it which modular array row to use CALL inp_sdetl(arr) # back from the input, reset the window just in case CURRENT WINDOW IS SCREEN # redisplay since ma_stat[arr].sdetl may have changed DISPLAY ma_stat[arr].* TO s_stat[scr].* # go to the next row NEXT FIELD ne END INPUT ... # NOTE: when updating the database, you of course would use the # value in ma_sdetl[].sdetl (ie: the long string). #---------------------------------------------------------------------# FUNCTION inp_sdetl(arr) # Arguments: Array value to do input to # Purpose: Input ma_sdetl[arr].sdetl in WORDWRAP mode # Returns: N/A #---------------------------------------------------------------------# DEFINE arr SMALLINT OPEN WINDOW sdetl AT 2,16 WITH FORM "sdetl" ATTRIBUTE(BORDER,COMMENT LINE LAST,MESSAGE LINE LAST) INPUT BY NAME ma_sdetl[arr].sdetl WITHOUT DEFAULTS ... END INPUT CLOSE WINDOW sdetl IF NOT int_flag THEN # reset the short string in the array field from # the long sring in the shadow array. LET ma_stat[arr].sdetl = ma_sdetl[arr].sdetl CLIPPED IF LENGTH(ma_sdetl[arr].sdetl) > sdetl_l THEN # If the string in the shadow array is longer that what is shown # in the array on screen, mark the noentry field with "..." LET ma_stat[arr].ne = "..." ELSE LET ma_stat[arr].ne = "" END IF ELSE LET int_flag = FALSE END IF END FUNCTION # inp_sdetl(arr)