标签:
如何在代码中获得控件的属性
1)创建节点:注意节点元素类型
2)在方法WDDOMODIFYVIEW获得view绑定在节点my_node上
method WDDOMODIFYVIEW . DATA LO_ND_MY_NODE TYPE REF TO IF_WD_CONTEXT_NODE. DATA LO_EL_MY_NODE TYPE REF TO IF_WD_CONTEXT_ELEMENT. DATA LS_MY_NODE TYPE WD_THIS->ELEMENT_MY_NODE. DATA LV_MY_VIEW LIKE LS_MY_NODE-MY_VIEW. * navigate from <CONTEXT> to <MY_NODE> via lead selection LO_ND_MY_NODE = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_MY_NODE ). * get element via lead selection LO_EL_MY_NODE = LO_ND_MY_NODE->GET_ELEMENT( ). lv_my_view = view. * get single attribute LO_EL_MY_NODE->SET_ATTRIBUTE( EXPORTING NAME = `MY_VIEW` VALUE = LV_MY_VIEW ). endmethod.
我们这边已button控件为例子,需要取得text的属性值
3)通过button事件,知道button的ID值,根据button的ID值通过view的相关方法知道button的所有属性及方法,在通过button的所有属性和方法得到button的属性值,以下有部分代码实现此功能。
METHOD onactionget_data. DATA lo_nd_my_node TYPE REF TO if_wd_context_node. DATA lo_el_my_node TYPE REF TO if_wd_context_element. DATA ls_my_node TYPE wd_this->element_my_node. DATA lv_my_view LIKE ls_my_node-my_view. FIELD-SYMBOLS <fs> TYPE wdr_event_parameter. FIELD-SYMBOLS <f1> TYPE wdr_event_parameter-value. DATA l_id TYPE string. FIELD-SYMBOLS <fs3> TYPE string. DATA cl_button TYPE REF TO cl_wd_button. DATA flag TYPE char1. DATA lv_text4 TYPE string. DATA: lv_len TYPE I, lv_fla TYPE char1. CLEAR flag. * navigate from <CONTEXT> to <MY_NODE> via lead selection lo_nd_my_node = wd_context->get_child_node( name = wd_this->wdctx_my_node ). lo_el_my_node = lo_nd_my_node->get_element( ). READ TABLE wdevent->parameters ASSIGNING <fs> WITH KEY name = ‘ID‘. ASSIGN <fs>-value->* TO <fs3>. “读取button属性值得button ID号 * get single attribute lo_el_my_node->get_attribute( EXPORTING name = `MY_VIEW` IMPORTING value = lv_my_view ). IF <fs3> IS ASSIGNED. cl_button ?= lv_my_view->get_element( <fs3> ). ”根据ID号通过View的方法,取得该ID是哪个控件的所有属性和方法等 ENDIF. ************************************************************************** DATA lo_nd_shuzi TYPE REF TO if_wd_context_node. DATA lo_el_shuzi TYPE REF TO if_wd_context_element. DATA ls_shuzi TYPE wd_this->element_shuzi. DATA lv_text LIKE ls_shuzi-text. DATA lv_text1 TYPE string. lo_nd_shuzi = wd_context->get_child_node( name = wd_this->wdctx_shuzi ). lo_el_shuzi = lo_nd_shuzi->get_element( ). cl_button->get_text( “得到该button的text属性值 RECEIVING value = lv_text1 ). lo_el_shuzi->get_attribute( EXPORTING name = `TEXT` IMPORTING value = lv_text ). CLEAR lv_len. lv_len = STRLEN( lv_text ). IF lv_len >= 2. lv_len = lv_len - 1. lv_fla = lv_text+lv_len(1). IF lv_fla <> ‘+‘ and lv_fla <> ‘*‘ and lv_fla <> ‘/‘ and lv_fla <> ‘-‘. wd_this->zjisuan( IMPORTING e_text = lv_text4 ). IF lv_text4 NA ‘+*/-‘. flag = ‘X‘. ENDIF. ENDIF. ENDIF. IF lv_text = ‘0‘ OR lv_text IS INITIAL. lv_text = lv_text1. ELSE. CONCATENATE lv_text lv_text1 INTO lv_text. CONDENSE lv_text NO-GAPS. ENDIF. IF lv_text1 = ‘C‘. lv_text = ‘0‘. ENDIF. IF flag = ‘X‘. lv_text = lv_text4. ENDIF. * set single attribute lo_el_shuzi->set_attribute( EXPORTING name = `TEXT` value = lv_text ). ENDMETHOD.
标签:
原文地址:http://www.cnblogs.com/caizjian/p/4329547.html