Get Class Name of object instance

Monkey Forums/Monkey Programming/Get Class Name of object instance

maverick69(Posted 2012) [#1]
Hi!

Is it possible with the reflection module to get the class name of an instance of an object during runtime?


slenkar(Posted 2012) [#2]
yes I think its just as simple as:
local myobj:tree
Print GetClass(myobj).Name
(prints "tree")



maverick69(Posted 2012) [#3]
Ah, missed that. Thanks ;)


maverick69(Posted 2012) [#4]
Hmmm, the example didn't work over here:

I've tried it and it prints out:

monkey.lang.Object


Samah(Posted 2012) [#5]
Because in that sample code, myobj is still null.
You need to assign it an instance of tree.


maverick69(Posted 2012) [#6]
Doesnt work either.


slenkar(Posted 2012) [#7]
did you import reflection?


marksibly(Posted 2012) [#8]
Hi,

This works here:

Import reflection

Class C
End

Function Main()
	Local c:=New C
	Print GetClass( c ).Name
End



maverick69(Posted 2012) [#9]
Oh thanks,

I had setup a wrong reflection filter. I'm sorry, but thanks for the help anyway ;)