Generic Object

BlitzMax Forums/BlitzMax Programming/Generic Object

Drey(Posted 2006) [#1]
Hey, I want a generic type in the field i can slap in other type into.

Here's an attempt. I'm sure i'm doing something simple wrong.


Graphics 800,600

Obj:UDO = New UDO




InputType = 1


If 	InputType = 1 Then

	Obj.Anytype = New IntType
	
ElseIf 	InputType = 2 Then
	
	Obj.Anytype = New FloatType
	
EndIf 


Obj.Anytype.Vari = 2

'DrawText String( Obj.Anytype.Vari ),0,0

Flip

WaitKey()



End




Type UDO

	Field Anytype:Object

End Type



Type IntType

	Field Vari

End Type


Type FloatType

	Field Vari#

End Type






gman(Posted 2006) [#2]
greetings Drey :) unfortunately BMAX is not quite as flexible as you are desiring. in this situation, before you can use a property on a type you must cast it to that type. in order to do what you are trying you must do something like:
If IntType(Obj.Anytype) Then IntType(Obj.Anytype).Vari = 2
If FloatType(Obj.Anytype) Then FloatType(Obj.Anytype).Vari=2

hope that helps...


Drey(Posted 2006) [#3]
Ah, thanks...it does kinda kill the idea i had though. I mean, this will still work for it..just kinda jacks up the efficency of it all. Maybe i'm being to tight on myself with optimization. Anyhow, thank you sir.