C
Colin Hemmings
Hi there,
I dont seem to be able to find the answer to this anywhere, so I am
wondering if anyone can help me. I am trying to see if there is a way of
referencing a object dynamically by passing it a variable.
For instance say I have an object called 'myObject', which contains
a public method called 'getTotal()'.
I also have a string variable called 'objectName', which contains
the string "myObject".
Is there a way of referencing 'myObject' using the contents of the
string variable. So is there a way to get the following line of code, or
something equivalent, to work:
objectName = "myObject";
objectName.getTotal();
Ive tried casting 'objectName' but that doesnt work, does anyone have
any suggestions?
I dont seem to be able to find the answer to this anywhere, so I am
wondering if anyone can help me. I am trying to see if there is a way of
referencing a object dynamically by passing it a variable.
For instance say I have an object called 'myObject', which contains
a public method called 'getTotal()'.
I also have a string variable called 'objectName', which contains
the string "myObject".
Is there a way of referencing 'myObject' using the contents of the
string variable. So is there a way to get the following line of code, or
something equivalent, to work:
objectName = "myObject";
objectName.getTotal();
Ive tried casting 'objectName' but that doesnt work, does anyone have
any suggestions?