Reflection Question

BlitzMax Forums/BlitzMax Programming/Reflection Question

zoqfotpik(Posted 2014) [#1]
Let's say I have a type TPerson, with a field name$.

I define one:
joe:TPerson = new TPerson

I want to automatically populate joe's name field with the name of the object, in this case "joe". In the docs for reflection, I could only find the Name field which would appear to return TPerson.

Any ideas?


degac(Posted 2014) [#2]
SuperStrict

Type Tperson
	Field name:String
End Type


Local joe:Tperson=New Tperson
Local id:TTypeId=TTypeId.ForObject(joe)

For Local fld:TField=EachIn id.Enumfields()
	
	Print "Field '"+fld.name()+"'"
	If fld.name()="name"
		fld.Set joe,String("Joe")
	End If
Next	

Print joe.name



zoqfotpik(Posted 2014) [#3]
Ahh, I understand now. Thanks a lot!