How can I test if an instance is of a certain type?
instance is of a certain type
BlitzMax Forums/BlitzMax Programming/instance is of a certain type 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.
Otherwise, you can as well use reflection and get its type and any type it extended.
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!
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
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
Ooh the cast method is neat. Noted that one down.