How to Get a value of a property at runtime via reflection?

Oh wow, ok that with the fields was just in addition^^, not such a badly needed Thing, but good to know how it works.

However, is the procedure with the “get_value” possible at runtime, carlo?

Because in an earlierer post, you told me, that you Need a different function pointer for every distinct result type.

Or am i able to do this:

TReadAccessor = private function(aSelf: Object): Object;

That the ReadAccessor will be dertermined at runtime?

Would burn to know this, because i want to get all properties at runtime of a class

Properties are actually easier than fields, but the upcoming build will have (preliminary!) support for Invoke:

which should let you do all this via reflection (since the read / write for a property is always a method).

Ahh ok, but how exactly will i call this?

Invoke(myClassInstance, ???);

Thanks!

Invoke(myClassInstance, <array of parameters>);

and what are the Parameters?

for instance,

var prms: [myCar.Name, myCar.Price, myCar.Velocity];
Invoke(myClassInstance, prms);

Could that be right??

well, whatever parameters your method takes?

i mean, i want to invoke the read-accessor of a property, did i understand this right?

And when i want to get all values from all properties of a class-instance, like in the example above with the car, how would i actually do this?

Honestly, i dont understand then the usage of the method, can u explain a bit^^

well. the getter of a simple property would not take any parameter, so you’d nt pass any (i.e. nil or an empty array):

propertyGetter.Invoke(myClassInstance, []);

the getter of an indexed property would take the indexer param(s), of course.

—marc

1 Like

thanks a lot marc

1 Like