MapInfo Pro Developers User Group

Expand all | Collapse all

Mapbasic Error - Alter Object cannot operate on an unitialized object variable

  • 1.  Mapbasic Error - Alter Object cannot operate on an unitialized object variable

    Posted 08-24-2018 00:12

    get this error when running an mbx in Mapbasic Include "MapBasic.def"

    Include "Menu.def"

     

    'assign brush/pen symbology for all but easements

    dim b1 as Brush

    b1 = makebrush (1,16777136,-1) 'Black colour, no fill

    dim p1 as Pen

    p1 = makepen (1,2,0) 'Black line

    dim x as Integer

    dim oUpdateObj as Object

     

     

    'Change Fill and Pen

    Open Table StrPathOt+"Easements.TAB" Interactive

     

    'Easements

    Select * from Easements where Str$(obj) = "Region" into NewStyle

    Fetch first from NewStyle

    x = 1

    Do

    oUpdateObj = NewStyle.obj

    Alter Object oUpdateObj Info OBJ_INFO_BRUSH, b1

    Alter Object oUpdateObj Info OBJ_INFO_PEN, p1

     

    Update NewStyle set Obj = oUpdateObj where RowID = x

     

    x = x + 1

     

    Fetch next from NewStyle

     

    Loop while x <= TableInfo(NewStyle,TAB_INFO_NROWS)

    Commit Table Easements

    The issue reported is on this line Alter Object oUpdateObj Info OBJ_INFO_BRUSH, b1



  • 2.  RE: Mapbasic Error - Alter Object cannot operate on an unitialized object variable

    Posted 08-23-2018 20:32

    Hi George,

    Are your easements polygons or lines?

    Are there any records in the "NewStyle" table?



  • 3.  RE: Mapbasic Error - Alter Object cannot operate on an unitialized object variable

    Posted 08-24-2018 00:45

    Hi, thanks for the quick reply.

     

    They are polygons and yes there are features selected.



  • 4.  RE: Mapbasic Error - Alter Object cannot operate on an unitialized object variable

    Posted 08-24-2018 02:39

    I tried running your code on a table of mine and it works so it must be something in your data that's making the tool break.

    I'd recommend that you rewrite your loop to look like this below. It's safer as it uses the true RowID and not a counter. It also loops on the existing records and skips potential deleted records:

    Fetch first from NewStyle

    Do Until EOT(NewStyle)

      oUpdateObj = NewStyle.obj

      x = NewStyle.ROWID

      Alter Object oUpdateObj Info OBJ_INFO_BRUSH, b1

      Alter Object oUpdateObj Info OBJ_INFO_PEN, p1

      Update NewStyle set Obj = oUpdateObj where RowID = x

      Fetch next from NewStyle

    Loop



  • 5.  RE: Mapbasic Error - Alter Object cannot operate on an unitialized object variable

    Posted 08-26-2018 23:29

    Thanks. That works and I made it into a sub for easy reuse. Code below if anyone finds in useful...

    Declare Sub Assign_Symbology(ByVal FileName as String, ByVal b1 as Brush, ByVal p1 as Pen)

    Declare Sub Main

     

    Sub Assign_Symbology (ByVal FileName as String, ByVal b1 as Brush, ByVal p1 as Pen)

    Dim   oUpdateObj as Object

    Dim x as Integer

     

    Open Table FileName as NewStyle

    Fetch first from NewStyle

    Do Until EOT(NewStyle)

     

     oUpdateObj = NewStyle.obj

     

     x = NewStyle.ROWID

     

     Alter Object oUpdateObj Info OBJ_INFO_BRUSH, b1

     

     Alter Object oUpdateObj Info OBJ_INFO_PEN, p1

     

     Update NewStyle set Obj = oUpdateObj where RowID = x

     

     Fetch next from NewStyle

     

    Loop

    Commit Table NewStyle

    Close Table NewStyle

    End Sub

     

    Sub Main

    Dim StrPathOt, FileName as String

    StrPathOt="G:\Projects\076_Monthly_DCDB_Update\Working\current\output\"

     

    'assign brush/pen symbology   for all but easements

       dim b1 as Brush

       dim p1 as Pen

       'Assing file to modify and symbology to set

     

          'Easements

          FileName = StrPathOt+"Easements.TAB"

          p1 = makepen (1,2,0)         'Black line

          b1 = makebrush (1,16777136,-1)   'Black colour, no fill

          Call Assign_Symbology (FileName, b1, p1)

          Print " Assigned symbology for: "+FileName

          'Drainage

          FileName = StrPathOt+"Drainage_DCDB"

          Call Assign_Symbology (FileName, b1, p1)

          Print " Assigned symbology for: "+FileName