‎2006 Oct 03 1:10 PM
I have a procedure that frees GUI controls. I have a lot of controls, and rather than have many procedures, I'd like to have 1 procedure that I call, passing an object reference.
It doesn't appear that through dynamic method call, I can do this with an instance method.
Can someone suggest a way to do this, without having a procedure for each control?
<b>* I want to pass g_r_editor as a parameter</b>
IF NOT g_r_editor IS INITIAL.
CALL METHOD g_r_editor->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
IF sy-subrc NE 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = text-011
txt2 = space
txt1 = text-005.
ENDIF.
FREE g_r_editor.
ENDIF.<b>Dynamic Method Call doc</b>
<a href="http://help.sap.com/saphelp_nw2004s/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm">http://help.sap.com/saphelp_nw2004s/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm</a>
‎2006 Oct 03 2:20 PM
Hello Bjorn
I would suggest the following approach:
(1) Collect all your GUI control instances in an itab whose line type is TYPE REF TO cl_gui_control.
(2) Define your "free" method:
LOOP AT mt_gui_controls INTO lo_gui_control.
* See if gui control was text editor
TRY.
lo_textedit ?= lo_gui_control.
CATCH cx_sy_move_cast_error INTO lo_error.
ENDTRY.
IF ( lo_error IS NOT BOUND ).
lo_textedit->free.
* ... your coding
CONTINUE.
ENDIF.
* See if gui control was tree
TRY.
lo_tree ?= lo_gui_control.
CATCH cx_sy_move_cast_error INTO lo_error.
ENDTRY.
* ...
ENDLOOP.The FREE methods are redefined in the subclasses. However, you could try to call lo_gui_control->free directly because I am not sure if the coding of the superclass or subclass is called (I cannot test this at the moment).
Regards
Uwe
‎2006 Oct 03 2:23 PM
Thanks. I ended up doing something similar. Since all the objects are subclasses, I don't think I need to worry about casting errors.
...
l_r_control = g_r_editor.
PERFORM free_controls
USING
l_r_control.
...
FORM free_controls
USING
p_r_control TYPE REF TO cl_gui_control.
IF NOT p_r_control IS INITIAL.
CALL METHOD p_r_control->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
IF sy-subrc NE 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = text-011
txt2 = space
txt1 = text-002.
ENDIF.
ENDIF.
ENDFORM. "free_controls