Array of Type conversions?

BlitzMax Forums/BlitzMax Beginners Area/Array of Type conversions?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

You are probably better off enumerating the TList directly when adding to the custom array - creating an Object[] array is an unnecessary step, at least in your example.

Something like (untested):
Function ListToArrayOf:Object(list:TList, of:TTypeId)
	Local arrayType:TTypeId = of.ArrayType()
	Local result:Object = arrayType.NewArray( list.Count() )
	Local idx:Int = 0
	For Local obj:Object = EachIn list
		arrayType.SetArrayElement result, idx, obj
	Next
	Return result
End Function


Anyway, if you know the target type before runtime, you should probably not use reflection, but have a specific function for each type you need to use.