instance is of a certain type

BlitzMax Forums/BlitzMax Programming/instance is of a certain type

VinceA(Posted 2007) [#1]
How can I test if an instance is of a certain type?


Dreamora(Posted 2007) [#2]
If you only need to know if it extends a certain type, trying to cast it is the fast and simple way.

Otherwise, you can as well use reflection and get its type and any type it extended.


Sledge(Posted 2007) [#3]
I guess you could give it a field that you could check, bung it in a list by itself then tot up how many of its type are present in that list with eachin, or investigate reflection (which I'm unfamiliar with but I dimly suspect might be able to facilitate this sort of thing). EDIT: Whoops, beaten to it!


VinceA(Posted 2007) [#4]
Thanks alot.. Works ..
Type Test1
End Type

Type Test2 Extends Test1
End Type

Local t2:Test2

Local t1:Test1

t2 = New Test2
t1 = New Test1

If Test2(t1) Then
Print " Same Type "
Else
Print "Not Same Type"
End If


If Test2(t2) Then
Print " Same Type "
Else
Print "Not Same Type"
End If


Sledge(Posted 2007) [#5]
Ooh the cast method is neat. Noted that one down.