Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to Access the class attribute that refers to some other class

Former Member
0 Kudos

Hi All,

I have one doubt on how to access the attributes of a class that has been declared as TYPE REF TO some other class or interface. In my case type ref to is pointing to some other class whose attribute is suppose to be set using the object of a class that inherits the first class. I am not having the code snippet to make my requirement even more clear but hope you could have got an idea of my problem.


When I tried accessing it directly through the object of the inherited class it gives a run-time error as the attribute is accessed via null reference.


Your help is needed to solve this.




Thanks in advance.

4 REPLIES 4

renandacosta
Explorer
0 Kudos

Hello,

Try this code:

data: ob_class2 type class2.

"Using casting to move de reference from class1 (superclass) to class2 (subclass).

ob_class2 ?= ob_class1.

"Now its possible access its methods.

ob_class2->set_name( 'Name' ).

Regards!

0 Kudos

Thank you !

This is the case only for inheritence. In my case I need to access the attribute which is contained in superclas that points to some other class. Moreover, Those two classes are are non-modifiable I need to use any external mechanism to perform this task.

Regards !

Former Member
0 Kudos

Hi,

You just need to create the instance of the attribute object. you can do it in the constructor of the superclass.

Regards,

0 Kudos

Thank You for your solution but can you please clarify in detail. My requirement is the two classes are already existing and I can not modify any of them. So, I cannot use constructor in superclass. Even using the statement "create object" for the same ref variable name that has been declared in superclass does not solve the purpose. The same run-time error is thrown that null reference is used.