[GIS] Finding the type of object in MapBasic (MapInfo)

mapbasicmapinfo

I am trying to write a MapBasic function to check whether or not an object can be used with the Overlap/AreaOverlap functions – I need to tell whether it's a closed shape or a line/arc/point/text object.

I have two questions.

  1. Is there an existing function that will do this?

  2. Why doesn't this work?

    Function IsObjectRegion(ObjAlias As Alias) As Logical
        Dim ObjectType As SmallInt
        Note OBJ_TYPE_POINT    ' This popup is displayed correctly
        Note "Crash Now."      ' This doesn't display. 
                               ' Instead you get an error that says "could not convert data".
        ObjectType = ObjectInfo(ObjAlias, OBJ_INFO_TYPE)
        Do Case ObjectType
            Case OBJ_TYPE_REGION
                IsObjectRegion = True
                print "Object WAS a region"
            Case OBJ_TYPE_RECT 
                IsObjectRegion = True
                print "Object WAS a region"
            Case OBJ_TYPE_ROUNDRECT 
                IsObjectRegion = True
                print "Object WAS a region"
            Case OBJ_TYPE_ELLIPSE
                IsObjectRegion = True
                print "Object WAS a region"
            Case Else
                IsObjectRegion = False
                print "Object was NOT a region"
        End Case
    End Function
    

Best Answer

I think you need to be passing an object variable into the function, not an alias which is just a column reference.

Function IsObjectRegion(selObj As Object) As Logical
Dim ObjectType As SmallInt

ObjectType = ObjectInfo(selObj, OBJ_INFO_TYPE)
Do Case ObjectType
...

If you wanted to test this out with the currently selected object, you could call the function like this:

    Dim test As Logical
    Dim testObject As Object
    testObject = Selection.Obj
    test = IsObjectRegion(testObject)

    Note test

This should return True/False.

James

Related Question