Android Question How to determine if Object is a scalar variable (String) or a Type?

Widget

Well-Known Member
Licensed User
Longtime User
I have a map that stores strings and occasionally a Type or two.
I would like to know if the value returned from Map1.Get("Key1") is a scalar value (String, Int etc.) or a Type.

I could of course check the object that the map returns, using If Stmts like:

B4X:
private locObj as Object
locObj = Map1.Get("key1")
if locObj is TMyType then
  private locMyType as TMyType
  locMyType = locObj
else
  if locObj is TMyType2 then
    private locMyType2 as TMyType2
    locMyType2 = locObj
  else
    'This is not TMyType or TMyType2, so it probably is a String?
    private locStr as String
    locStr = locObj
  end if
end if

Is there a simple way to determine if the value returned from Map1.Get into locObj is a scalar variable (String etc.) or something else?

If there is no easy way to do it, then I will simply check for every possible Type that it could be.

TIA
P.S. This is more of a theoretical example rather than a practical example. I know I could change the map's Key to suffix on the Type of variable that stored for that entry, but this has me wondering if there is a simple way of determining if an object contains a scalar value.
 

DonManfred

Expert
Licensed User
Longtime User
B4X:
log(GetType(locObj))
?
 
Upvote 0
Top