Com_Owner Com_Ancestor and Com_Self

Visual LANSA

#Com_Owner, #Com_Ancestor and #Com_Self

The generic name #Com_Owner can be used to refer to the current component. In the context of inheritance there are two other generic names you can use for components: #Com_Ancestor and #Com_Self.

#Com_Ancestor is a generic reference to the ancestor of the current component and #Com_Self is a generic reference to the currently executing component.

#Com_Owner and #Com_Self

To see in what way #Com_Owner and #Com_Self differ create two reusable parts with this code:

Button 3

This button reusable part contains a method MethodOne which displays a message saying Hello. The message is displayed when this button (Button3, in other words #Com_Owner) is clicked.

FUNCTION options(*DIRECT)
BEGIN_COM role(*EXTENDS #PRIM_PHBN) CAPTION('Button 3') HEIGHT(24) WIDTH(185)
 
MTHROUTINE name(MethodOne)
USE builtin(MESSAGE_BOX_SHOW) with_args(OK OK INFO '' 'Hello') to_get(#STD_OBJ)
ENDROUTINE
 
EVTROUTINE handling(#COM_OWNER.Click)
INVOKE method(#com_owner.methodone)
ENDROUTINE
 
END_COM

 

 

Button 4

This button reusable part inherits from Button3 and redefines MethodOne so that the message says Bye.

FUNCTION options(*DIRECT)
BEGIN_COM role(*EXTENDS #BUTTON3) CAPTION('Button 4') HEIGHT(26) WIDTH(176)
 
MTHROUTINE name(MethodOne) options(*redefine)
USE builtin(MESSAGE_BOX_SHOW) with_args(OK OK INFO '' 'Bye') to_get(#STD_OBJ)
ENDROUTINE
 

END_COM

 

 

 

 

Add these buttons to a form and compile and execute the form. Click on both buttons. They both display a message saying 'Hello':

In other words the redefined method which would display the message 'Bye' is not used for Button 4 because the Click event defined in Button 3 invokes the method in the component where it is defined (#Com_Owner):

INVOKE method(#com_owner.methodone)

 

Next change the invoke command in the Click event of Button 3 to use #Com_Self instead of #Com_Owner so that the Click event invokes the method in the component where the event is executed:

INVOKE method(#com_self.methodone)

 

Compile Button 3 and execute your form again. This time when you click on Button 4, the redefined method is used and the message 'Bye' is displayed:

#Com_Ancestor

If you want to invoke a method in an ancestor component, you can refer to it by qualifying the name of the method using the generic name #com_ancestor.

For example, to continue with the above example, you can invoke the MethodOne method in Button 3 from the redefined MethodOne in Button 4 like this:

MTHROUTINE name(MethodOne) options(*redefine)
INVOKE method(#com_ancestor.methodone)
USE builtin(MESSAGE_BOX_SHOW) with_args(OK OK INFO '' 'Bye') to_get(#STD_OBJ)
ENDROUTINE

 

Compile Button 4 and run your test form. When you click on Button 4 first the MethodOne from the ancestor Button 3 is invoked:

And then when you click OK, the Message_Box_Show Built-In Function showing the text 'Bye' defined in Button 4 is displayed:

Ý 6.21.4 Advanced Inheritance Topics