Android Question [SOLVED] How to check Object type?

techknight

Well-Known Member
Licensed User
Longtime User
Is it possible to determine what type of object is passed in an Object variable?

I am probably doing this wrong, but I have a subroutine that if successful, returns a map. If its not successful, it returns a Boolean of False.

I would like to check the item type without calling the subroutine twice. once to determine its not false, and yet again to get the data.

any ideas?
 

techknight

Well-Known Member
Licensed User
Longtime User
I tried that, but I cant find a table anywhere what its return is supposed to be?

Because If GetType(M) = "Map" didnt work.

I guess I will have to log it, and do it that way, As long as it doesnt change.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Or if the only two types are Map (Which must be initialized) or Boolean then you can do
B4X:
If ReturnValue Is Map Then
        Log("Map")
    Else
        Log("Boolean")
    End If
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
I can't imagine they would ever change, so build your own list by logging types you're interested in, and then use their values. Or do what stevel05 suggested, that might be cleaner for you.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
Tried both suggestions, Both work fine. Steve's method is a little bit easier/cleaner yes, but I do have some custom types so the lookup table method might work better for me.

Anyways, thanks guys!
 
Upvote 0
Top