一般的COMBOX我们一般的是直接在per里面写item属性,如下代码:
- COMBOBOX tc_qcjj08 = FORMONLY.tc_qcjj08,COMMENTS ='Enter 0 1 2 4 8 12 ',
- ITEMS=(("0","每批/次"),("1","1H/次"),
- ("2","2H/次"),("4","4H/次"),
- ("6","6H/次"),("8","8H/次"),("12","12H/次"),
- ("24","24H/次"));
COMBOBOX tc_qcjj08 = FORMONLY.tc_qcjj08,COMMENTS ='Enter 0 1 2 4 8 12 ',
ITEMS=(("0","每批/次"),("1","1H/次"),
("2","2H/次"),("4","4H/次"),
("6","6H/次"),("8","8H/次"),("12","12H/次"),
("24","24H/次"));
一直很想试下动态绑定item值,今天正好写程序用到COMBOX,结果就试了下,
不是很难,主要是4gl代码实现。详细实现如下。
per画面定义一个COMBOX的组件
- COMBOBOX tc_qcjj01 = FORMONLY.tc_qcjj01 TYPE VARCHAR,NOT NULL,REQUIRED;
COMBOBOX tc_qcjj01 = FORMONLY.tc_qcjj01 TYPE VARCHAR,NOT NULL,REQUIRED;
然后在4gl代码中写一个单独的函数来处理COMBOX中的item,代码如下:
- ##################################################
- # Description : 撷取彩妆分群码填充COMBOX
- # Date & Author : 2012/09/26 by FMX
- ##################################################
- FUNCTION tc_qcjj01_cmd()
- DEFINE li_gbi_count SMALLINT
- DEFINE lc_ima06 LIKE ima_file.ima06
- DEFINE lc_imz02 LIKE imz_file.imz02
- DEFINE lsb_item base.StringBuffer
- DEFINE lsb_item2 base.StringBuffer
- LET lsb_item = base.StringBuffer.create()
- LET lsb_item2 = base.StringBuffer.create()
- DECLARE l_cmdCurs2 CURSOR FOR
- SELECT DISTINCT ima06,imz02
- FROM ima_file,imz_file
- WHERE ima06=imz01 AND imz02 LIKE '%彩妆%'
- ORDER BY 1
- FOREACH l_cmdCurs2 INTO lc_ima06,lc_imz02
- CALL lsb_item.append(lc_ima06 CLIPPED || ",")
- CALL lsb_item2.append(lc_ima06 CLIPPED || " (" || lc_imz02 CLIPPED || "),")
- END FOREACH
- CALL cl_set_combo_items("tc_qcjj01",lsb_item.toString(), lsb_item2.toString())
- END FUNCTION
##################################################
# Description : 撷取彩妆分群码填充COMBOX
# Date & Author : 2012/09/26 by FMX
##################################################
FUNCTION tc_qcjj01_cmd()
DEFINE li_gbi_count SMALLINT
DEFINE lc_ima06 LIKE ima_file.ima06
DEFINE lc_imz02 LIKE imz_file.imz02
DEFINE lsb_item base.StringBuffer
DEFINE lsb_item2 base.StringBuffer
LET lsb_item = base.StringBuffer.create()
LET lsb_item2 = base.StringBuffer.create()
DECLARE l_cmdCurs2 CURSOR FOR
SELECT DISTINCT ima06,imz02
FROM ima_file,imz_file
WHERE ima06=imz01 AND imz02 LIKE '%彩妆%'
ORDER BY 1
FOREACH l_cmdCurs2 INTO lc_ima06,lc_imz02
CALL lsb_item.append(lc_ima06 CLIPPED || ",")
CALL lsb_item2.append(lc_ima06 CLIPPED || " (" || lc_imz02 CLIPPED || "),")
END FOREACH
CALL cl_set_combo_items("tc_qcjj01",lsb_item.toString(), lsb_item2.toString())
END FUNCTION
cl_set_combo_items()函数是标准的系统共享函数,在这里也把代码贴出来:
- # Prog. Version..: '3.10.06-07.03.05(00003)' #
- # Program name : cl_set_combo_items.4gl
- # Program ver. : 7.0
- # Description : 动态设定ComboBox的Item.
- # Date & Author : 2003/07/02 by Hiko
- # Memo :
- # Sample : CALL cl_set_combo_items("oea08", "1,2", "Local Order,Export Order")
- # Modify :
- # Modify.........: FUN-640240 06/05/17 Echo 自动执行确认功能
- # Modify.........: No:FUN-6C0017 06/12/13 By jamie 程式开头增加''database ds '
- DATABASE ds #FUN-6C0017
- GLOBALS "../../config/top.global"
- FUNCTION cl_set_combo_items(ps_field_name, ps_values, ps_items)
- DEFINE ps_field_name,ps_values,ps_items STRING
- DEFINE lcbo_target ui.ComboBox
- DEFINE lst_values,lst_items base.StringTokenizer
- DEFINE ls_msg VARCHAR(100)
- WHENEVER ERROR CALL cl_err_msg_log
- #FUN-640240
- IF g_bgjob='Y' THEN
- RETURN
- END IF
- #END FUN-640240
- #MOD-540134
- LET ps_field_name=ps_field_name.trim()
- #MOD-520002
- LET ps_values=ps_values.trim()
- LET ps_items=ps_items.trim()
- LET lcbo_target = ui.ComboBox.forName(ps_field_name)
- IF lcbo_target IS NULL THEN
- SELECT ze03 INTO ls_msg FROM ze_file WHERE ze01 = 'lib-031' AND ze02 = g_lang
- CALL cl_err(ps_field_name, "lib-031", 1)
- RETURN
- ELSE
- CALL lcbo_target.clear()
- END IF
- LET lst_values = base.StringTokenizer.create(ps_values, ",")
- LET lst_items = base.StringTokenizer.create(ps_items, ",")
- WHILE lst_values.hasMoreTokens()
- CALL lcbo_target.addItem(lst_values.nextToken(), lst_items.nextToken())
- END WHILE
- END FUNCTION
# Prog. Version..: '3.10.06-07.03.05(00003)' #
# Program name : cl_set_combo_items.4gl
# Program ver. : 7.0
# Description : 动态设定ComboBox的Item.
# Date & Author : 2003/07/02 by Hiko
# Memo :
# Sample : CALL cl_set_combo_items("oea08", "1,2", "Local Order,Export Order")
# Modify :
# Modify.........: FUN-640240 06/05/17 Echo 自动执行确认功能
# Modify.........: No:FUN-6C0017 06/12/13 By jamie 程式开头增加''database ds '
DATABASE ds #FUN-6C0017
GLOBALS "../../config/top.global"
FUNCTION cl_set_combo_items(ps_field_name, ps_values, ps_items)
DEFINE ps_field_name,ps_values,ps_items STRING
DEFINE lcbo_target ui.ComboBox
DEFINE lst_values,lst_items base.StringTokenizer
DEFINE ls_msg VARCHAR(100)
WHENEVER ERROR CALL cl_err_msg_log
#FUN-640240
IF g_bgjob='Y' THEN
RETURN
END IF
#END FUN-640240
#MOD-540134
LET ps_field_name=ps_field_name.trim()
#MOD-520002
LET ps_values=ps_values.trim()
LET ps_items=ps_items.trim()
LET lcbo_target = ui.ComboBox.forName(ps_field_name)
IF lcbo_target IS NULL THEN
SELECT ze03 INTO ls_msg FROM ze_file WHERE ze01 = 'lib-031' AND ze02 = g_lang
CALL cl_err(ps_field_name, "lib-031", 1)
RETURN
ELSE
CALL lcbo_target.clear()
END IF
LET lst_values = base.StringTokenizer.create(ps_values, ",")
LET lst_items = base.StringTokenizer.create(ps_items, ",")
WHILE lst_values.hasMoreTokens()
CALL lcbo_target.addItem(lst_values.nextToken(), lst_items.nextToken())
END WHILE
END FUNCTION
此函数写好后,在MAIN函数中直接调用即可。运行效果如下图:
有兴趣的可以试试