2007 Apr 16 4:40 PM
Dear experts,
Please help!
I have two classes in my program:
Class "screen_init" and class "screen_handler".
Each class has its own constructor plus other methods.
For example class "screen_handler" has methods "constructor", "handle_node_double_click",
"handle_picture_double_click", "handle_textedit_double_click".
In Constructor of class "screen_init" I do:
- define event_handler:
Data event_handler type ref to screen_handler.
- create an object event_handler:
Create object event_handler
exporting textedit = textedit
tree = tree.In definition section of class "screen_handler" I define constructor as:
methods: constructor importing
textedit type ref to cl_gui_textedit
tree type ref to cl_gui_simple_tree.When the program creates an object event_handler - then the Constructor of class "screen_handler" is run.
The problem is that textedit and tree are successfully received in the Constructor of "screen_handler" class. But when it gets to any other method of "screen_handler" class ( method "handle_textedit_double_click", for example) - these objects are empty.
I need tree object when method "handle_textedit_double_click" is run - so I could read textedit and then repopulate the tree depending on textedit value.
Please note that textedit and tree are defined in both classes in Public section:
class screen_init definition.
public section.
data: textedit type ref to CL_GUI_TEXTEDIT,
tree type ref to cl_gui_simple_tree.
class screen_handler definition.
public section.
data: textedit type ref to CL_GUI_TEXTEDIT,
tree type ref to cl_gui_simple_treeThank you,
Tatyana.
2007 Apr 16 9:28 PM
Hello Tatyana
The only possible reason I see is that you do no save the imported instance into the public instance attributes. Presumably the coding of your CONSTRUTOR method is missing the following coding:
Recommendation: rename your instance attribute, e.g.
class screen_init definition.
public section.
data: mo_textedit type ref to CL_GUI_TEXTEDIT,
mo_tree type ref to cl_gui_simple_tree.
class screen_handler definition.
public section.
data: mo_textedit type ref to CL_GUI_TEXTEDIT,
mo_tree type ref to cl_gui_simple_tree
" Create event handler instance
Create object event_handler
exporting textedit = textedit " instance IS BOUND
tree = tree. " instance IS BOUND
" Here we are inside the CONSTRUCTOR
method CONSTRUCTOR.
me->mo_textedit = textedit. " save the imported instance to instance attribute
me->mo_tree = tree. " dito
endmethod.Regards
Uwe
Hello Tatyana
The only possible reason I see is that you do no save the imported instance into the public instance attributes. Presumably the coding of your CONSTRUTOR method is missing the following coding:
Recommendation: rename your instance attribute, e.g.
class screen_init definition.
public section.
data: mo_textedit type ref to CL_GUI_TEXTEDIT,
mo_tree type ref to cl_gui_simple_tree.
class screen_handler definition.
public section.
data: mo_textedit type ref to CL_GUI_TEXTEDIT,
mo_tree type ref to cl_gui_simple_tree
" Create event handler instance
Create object event_handler
exporting textedit = textedit " instance IS BOUND
tree = tree. " instance IS BOUND
" Here we are inside the CONSTRUCTOR
method CONSTRUCTOR.
me->mo_textedit = textedit. " save the imported instance to instance attribute
me->mo_tree = tree. " dito
endmethod.Regards
Uwe
2007 Apr 16 9:28 PM
Hello Tatyana
The only possible reason I see is that you do no save the imported instance into the public instance attributes. Presumably the coding of your CONSTRUTOR method is missing the following coding:
Recommendation: rename your instance attribute, e.g.
class screen_init definition.
public section.
data: mo_textedit type ref to CL_GUI_TEXTEDIT,
mo_tree type ref to cl_gui_simple_tree.
class screen_handler definition.
public section.
data: mo_textedit type ref to CL_GUI_TEXTEDIT,
mo_tree type ref to cl_gui_simple_tree
" Create event handler instance
Create object event_handler
exporting textedit = textedit " instance IS BOUND
tree = tree. " instance IS BOUND
" Here we are inside the CONSTRUCTOR
method CONSTRUCTOR.
me->mo_textedit = textedit. " save the imported instance to instance attribute
me->mo_tree = tree. " dito
endmethod.Regards
Uwe
2007 Apr 17 12:21 AM
I agree with Uwe.
Just a small clarification. I think the attributes need to be decalred either as private or protected attribiutes else the concept of having a OOP program is not very much justified.
Cheers
Kareem
2007 Apr 17 7:23 AM
... and I agree with Kareem.
However, even SAP standard classes have often public instance attributes (e.g. CL_REBD_BUILDING->ms_detail) but then they are defined as <b>read-only</b>.
Regards
Uwe
2007 Apr 17 3:50 PM
Guys,
I can't express how much you helped me.
I am new to ABAP though with the years with other programming languages experience.
The 2 lines below were the key to resolve the problem.
me->textedit = textedit. " save the imported instance to instance
"attribute
me->tree = tree. " ditoThank you very much!
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |