Reflection question

BlitzMax Forums/BlitzMax Programming/Reflection question

JoshK(Posted 2009) [#1]
I want to set all fields in an object of type "TBuffer" to Null. Is this correct?:

	Method FreeBuffers() {hidden}
		Local typeid:TTypeId
		Local fieldtypeid:TTypeId
		Local f:TField
		Local o:Object
		typeid=TTypeId.ForObject(Self)
		For f=EachIn typeid.fields()
			o=f.get(Self)
			If o
				fieldtypeid=TTypeId.ForObject(o)
				If fieldtypeid.name()="TBuffer"			
					f.Set(Self,Null)
				EndIf
			EndIf
		Next
		GCCollect()
	EndMethod



N(Posted 2009) [#2]
Change typeid.Fields() to typeid.EnumFields() and it should be correct, although this will be significantly slower than just setting the fields to null normally.