Android Question Use Reflection on istance of a custom class

Luca Rinaldoni

Member
Licensed User
Hi, I try to use Reflector for take a value from a field of my object.
I read this: https://www.b4x.com/android/help/reflection.html#reflector

I've a class Product and I create an istance of it.

Dim product As Product
product.Initialize
product.COD_RIORD = "1234567890"
product.CODEAN = "501489592615"
product.DESCRIPTION = "STAR WARS FIGURES..."
product.PRICE = "6,45"

Every fields have set and get in class.
Now, I try to use Reflector.

Dim x As Reflector
Dim var as string = "PRICE"

x.Target = product
Log(x.GetField(sf.Lower(var)))

Last istruction raise an exception.

Can you help me?

Matteo
 

Luca Rinaldoni

Member
Licensed User
Ops.. sorry for inconvenience.

For my question, I've found a workaround.
mObjectTarget is an instance of my class; var is name of property.
For extract value, I must use CallSub and "get" before name of property (implemented with set and get).

B4X:
value = CallSub(mObjectTarget, "get" & var)

Is it correct like workaround of Reflection?


Matteo
 
Upvote 0
Top