How to Check for a given type?

BlitzMax Forums/BlitzMax Beginners Area/How to Check for a given type?

Rozek(Posted 2006) [#1]
Hello!

Please excuse this probably *very* basic question, but I could not find the answer neither by reading through the online help nor by searching this forum:

- how do I determine, whether a given variable is of a given type?
- is there an "is" operator?

Examples
- a is byte
- a is TList

Thanks in advance for any responses!


fredborg(Posted 2006) [#2]
If TList(hello) Then Print "hello is a TList"
If TPixmap(hello) Then Print "hello is a TPixmap"
etc.
Notice that byte, int, float, etc. may be converted to each other by using a similar approach, so I'm not sure how you would handle that...


Azathoth(Posted 2006) [#3]
Only objects can be cast back and forth from base types including strings and arrays.

a=TList(b)
if 'a' contains a reference 'b' is a type of TList otherwise 'a' contains null.


Rozek(Posted 2006) [#4]
Hello Mikkel! Hello Paul!

Thanks for the quick response...

It looks as if I would have to try a type casting and check if that fails...