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

island
oxygene

(SH) #21

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


(Carlo Kok) #22

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).


(SH) #23

Ahh ok, but how exactly will i call this?

Invoke(myClassInstance, ???);

Thanks!


(marc hoffman) #24

Invoke(myClassInstance, <array of parameters>);


(SH) #25

and what are the Parameters?

for instance,

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

Could that be right??


(marc hoffman) #27

well, whatever parameters your method takes?


(SH) #28

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^^


(marc hoffman) #29

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


(SH) #30

thanks a lot marc