Field is zero! (Reflection)
BlitzMax Forums/BlitzMax Programming/Field is zero! (Reflection)
| ||
I'm trying to use reflection to build my system, but whenever I try to retrieve a value from a field, it comes back as zero! :oType Test Field Test:Int = 5 EndType Local id:TTypeId = TTypeId.ForName("Test") For Local fld:TField = EachIn id.EnumFields() Print "Field: " + fld.Name() + " = " + fld.GetInt(Null) Next By my logic, that should say "Field: Test = 5" but instead it's "= 0", WHY?! D: |
| ||
Well, If I'm not wrong there is any object of type 'Test', so no field with value '5'Type Test Field myfield:Int = 5 Field two:String="This is a string 'two'" EndType Local id:TTypeId = TTypeId.ForName("Test") Local myobj:Test=New Test For Local fld:TField = EachIn id.EnumFields() Print "Field: <" + fld.name() + "> <" +fld.TypeId().Name()+"> = "+fld.GetString(myobj) Next Last edited 2011 |
| ||
Yeah, I was worried that'd be the issue... Isn't there a way around this without creating an instance of the type? I noticed that it works if you first use fld.SetInt(Null,5) it'll work just fine! |
| ||
I noticed that it works if you first use fld.SetInt(Null,5) it'll work just fine! Well, to me it seems like a bug: as there's no object, no result should be available or changeable |
| ||
Hiya guys. It's not a bug. It's working correct in the same that you can set a default value in the type definition but instead you can use reflection to do the same thing. |