TEXT文本编辑框4 点击按钮读取文本框内容到内表

*&---------------------------------------------------------------------*
*& Report ZTEST_CWBK
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------* REPORT ztest_cwbk.
CONSTANTS:
line_length TYPE i VALUE .
DATA: ok_code LIKE sy-ucomm.
DATA:
* Create reference to the custom container
custom_container TYPE REF TO cl_gui_custom_container,
* Create reference to the TextEdit control
editor TYPE REF TO cl_gui_textedit,
repid LIKE sy-repid. * Utillity table to load texts **********************************************************************
TYPES: BEGIN OF t_texttable, line(line_length) TYPE c, END OF t_texttable.
DATA: i_texttable TYPE TABLE OF t_texttable, g_loaded() TYPE c. ********************************************************************** * Impmenting events
**********************************************************************
DATA:
event_type() TYPE c, * Internal table for events that should be registred i_events TYPE cntl_simple_events, * Structure for oneline of the table wa_events TYPE cntl_simple_event.
*---------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------* CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
catch_dblclick FOR EVENT dblclick
OF cl_gui_textedit IMPORTING sender.
ENDCLASS.
CLASS lcl_event_handler IMPLEMENTATION.
METHOD catch_dblclick.
DATA:
from_line TYPE i,
from_pos TYPE i,
to_line TYPE i,
to_pos TYPE i,
wa_texttable TYPE t_texttable.
* event_type = 'Event DBLCLICK raised'.
* Reacting to the system event
call method cl_gui_cfw=>set_new_ok_code
exporting new_code = 'SHOW'.
* Read the position of the double click
CALL METHOD sender->get_selection_pos
IMPORTING
from_line = from_line
from_pos = from_pos
to_line = to_line
to_pos = to_pos.
* table that contains text
IF NOT g_loaded IS INITIAL.
CALL METHOD sender->get_text_as_r3table
IMPORTING table = i_texttable.
* Read the line of the internal table that was clicked
READ TABLE i_texttable INDEX from_line INTO wa_texttable.
IF sy-subrc <> .
EXIT.
ENDIF.
IF wa_texttable+() CS '*'.
SHIFT wa_texttable.
ELSEIF wa_texttable+() NS '*'.
SHIFT wa_texttable RIGHT.
wa_texttable+() = '*'.
ENDIF.
modify i_texttable from wa_texttable index from_line.
* Reload texts from h einternal table
perform load_texts.
ENDIF.
ENDMETHOD. ENDCLASS. START-OF-SELECTION.
SET SCREEN ''.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
DATA str TYPE c.
DATA sline TYPE i.
CASE ok_code.
WHEN 'EXIT'.
LEAVE TO SCREEN .
WHEN 'IMP'.
* event_type = 'System dblclick'.
* perform load_texts.
PERFORM get_texts. "读取文本框到内表
ENDCASE.
* Call the Dispacth method to initiate application event handling
* call method cl_gui_cfw=>Dispatch. ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'MAIN100'.
IF editor IS INITIAL.
repid = sy-repid.
* Create obejct for custom container
CREATE OBJECT custom_container
EXPORTING
container_name = 'MYCONTAINER1'
EXCEPTIONS
cntl_error =
cntl_system_error =
create_error =
lifetime_error =
lifetime_dynpro_dynpro_link =
OTHERS = .
IF sy-subrc <> .
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Create obejct for the TextEditor control
CREATE OBJECT editor
EXPORTING
wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position
wordwrap_position = line_length
wordwrap_to_linebreak_mode = cl_gui_textedit=>true
parent = custom_container
EXCEPTIONS
error_cntl_create =
error_cntl_init =
error_cntl_link =
error_dp_create =
gui_type_not_supported =
OTHERS = .
IF sy-subrc <> .
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF. * Link the event handler method to the event and the
* TextEdit control
SET HANDLER lcl_event_handler=>catch_dblclick FOR editor.
* Register the event in the internal table i_events
wa_events-eventid = cl_gui_textedit=>event_double_click.
* wa_events-appl_event = 'X'. "This is an application event
wa_events-appl_event = space. "This is a system event
append wa_events to i_events.
* Pass the table to the TextEdit control using method
* set_registred_events
call method editor->set_registered_events
exporting events = i_events.
ENDIF. ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Form LOAD_TEXTS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form LOAD_TEXTS .
TYPES:
BEGIN OF t_texttable,
line(line_length) TYPE c,
END OF t_texttable.
DATA
i_texttable TYPE TABLE OF t_texttable.
* Create internal table with texts
APPEND 'This a method that fills the TextEdit control' TO i_texttable.
APPEND 'with a text.' TO i_texttable.
DO TIMES.
APPEND 'hallo world !' TO i_texttable.
ENDDO.
* Load TextEdit control with texts
CALL METHOD editor->set_text_as_r3table
EXPORTING table = i_texttable.
IF sy-subrc > .
* Display an error message
EXIT.
ENDIF.
* All methods that operates on controls are transferred to the frontend * by a RFC calls. the method FLUSH is used to determine when this is done.
CALL METHOD cl_gui_cfw=>flush.
IF sy-subrc > .
* Display an error message
ENDIF. endform. " LOAD_TEXTS
*&---------------------------------------------------------------------*
*& Form GET_TEXTS
*&---------------------------------------------------------------------*
form GET_TEXTS .
TYPES:
BEGIN OF t_texttable,
line(line_length) TYPE c,
END OF t_texttable.
DATA
i_texttable TYPE TABLE OF t_texttable. *该方法可以读取编辑文本框输入的内容
CALL METHOD editor->get_text_as_r3table
IMPORTING table = i_texttable. endform. " GET_TEXTS
上一篇:python----------反射和设计模式


下一篇:并发编程 - 线程 - 1.开启线程的两种方式/2.进程与线程的区别/3.Thread对象的其他属性或方法/4.守护线程