MapInfo Pro Developers User Group

 View Only
  • 1.  Mapbasic Find succeeds with popup error

    Posted 08-22-2023 20:03

    Hi all, for performance reasons I'm revamping how our application interacts with MapInfo 17.0.2 as our integrated map display.  A primary aspect of this is starting to use the MapBasic "Find" command which isn't working seamless for us yet.  Below is a list of the commands being run to illustrate the problem, with all spaces and quotes just as we pass them into MapInfoApplicationHost::RunMapBasicCommand (escape-characters to make that happen are not shown here).  However, running them in MapInfo Pro doesn't reproduce the issue.

    //The setup...
    Create Table TRG_HST_1 (trackId Integer ,REPCODE Integer  ) File "C:\temp\MItables\TRG_HST_1"
    Create Map For TRG_HST_1
    Set Table TRG_HST_1 FastEdit On
    Create Index On TRG_HST_1(trackId)
    Commit Table TRG_HST_1

    //here's the line we use to show the table in our existing window, probably not relevant to the problem
    Set Map Window 3000 Layer "TRG_HST_1" Editable Off Selectable On Zoom (1,100000) Off Label Position Center Font("Arial",0,12,16776960) Pen(1,2,0) With  Str$(trackId) Parallel On Visibility Off Auto Off Overlap Off Duplicates Off Offset 3 Display Graphic

    //Add a row...
    Set Table TRG_HST_1 REDRAW OFF
    Dim TargetHistory As Object
    Create Pline Into Variable TargetHistory 2 (-77.48300, 17.96100) (-77.53800, 18.10500) Pen(2,2,16777215)
    Insert Into TRG_HST_1 (trackId,REPCODE,Object ) Values ( 17187,2,TargetHistory )
    Find Using TRG_HST_1(trackId)

    //Find it...
    Find "17187"

    Now the problem behavior... when we execute a find command (MapInfoApplicationHost::Instance->RunMapBasicCommand("Find \"17187\" Interactive", true, true)) we get the right rowID (CMD_INFO_FIND_ROWID) out of it, and things look good (CMD_INFO_FIND_RC = "11").  But still it also shows a popup error that says "Variable or Field trackId not defined."


    Other clue...  Running Find 17187 (no quotes) causes the error "Variable or Field trackId not defined.  Expression does not evaluate to a character string."  However, using MapInfo Pro to look at the table structure, the trackId column type is indeed Integer so I don't understand why the quotes are needed.


    Side note...  Changing the third parameter of RunMapBasicCommand [reportErrorsToMapBasic] to false seems to suppress the popup usually (maybe 99.9%), but not always and the popup gets displayed from elsewhere in MapInfo without our code in the stack, so maybe asynchronously queued for display when nothing else is going on.  Counting calls to Find doesn't reveal any predictability to when the popup will be seen in this case.



    ------------------------------
    Bryan Kubishta
    Raytheon
    ------------------------------


  • 2.  RE: Mapbasic Find succeeds with popup error

    Employee
    Posted 08-23-2023 02:12

    Hi Bryan

    The Find command is built to search for addresses and I think it expects string values.

    From the syntax of the statement, you can also see that it expects a string expression for the address value.

    Find address [ , region ] [ Interactive ]

    address is a string expression representing the name of a map object to find; to find the intersection of two streets, use the syntax: streetname && streetname.

    region is the name of a region object which refines the search.

    Would it be possible to use a Char column for the value you are searching for instead of an Integer column?



    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------



  • 3.  RE: Mapbasic Find succeeds with popup error

    Posted 08-25-2023 15:48
    Edited by Bryan Kubishta 08-25-2023 16:29

    Hi Peter, thank you so much for the response!  Changing the trackId column to a string seems to have changed the problem.  The same error message popup is randomly seen, and seen every time if reportErrorsToMapBasic is true.  But the difference is this time I caught it also happening sometimes when we run the "Find Using TRG_HST_1(trackId)" command.

    So right now the relevant MapBasic calls are these:


    Create Table TRG_HST_1 (trackId Char(10) ,REPCODE Integer  ) File "C:\temp\MItables\TRG_HST_1"
    Create Map For TRG_HST_1
    Create Index On TRG_HST_1(trackId)
    Commit Table TRG_HST_1

    Add Map Window 3000 Auto Layer TRG_HST_1
    Set Map Window 3000 Layer "TRG_HST_1" Editable Off Selectable On Zoom (1,100000) Off Label Position Center Font("Arial",0,12,16776960) Pen(1,2,0) With  Str$(trackId) Parallel On Visibility Off Auto Off Overlap Off Duplicates Off Offset 3 Display Graphic

    //example insertion
    Set Table TRG_HST_1 REDRAW OFF
    Dim TargetHistory As Object
    Create Pline Into Variable TargetHistory 5 (-56.89900, 38.64200) (-56.82300, 38.65000) (-56.74600, 38.65600) (-56.66700, 38.65900) (-56.65500, 38.64400) Pen(2,2,16776960)
    Insert Into TRG_HST_1 (trackId,REPCODE,Object ) Values ( "15708",2,TargetHistory )


    //example find
    Find Using TRG_HST_1(trackId)
    Find "15708"

    Set Table TRG_HST_1 REDRAW ON

    Are the error popups somehow queued when reportErrorsToMapBasic is false, and then shown when it's true?  I'm manually controlling it and at least once even saw the same error shown when executing the Insert command, and the Dim command, above.  There's a lot more happening than the above after table creation.  We are potentially executing hundreds of commands per second so the popups happening now might not be coming from where we think?



    ------------------------------
    Bryan Kubishta
    Raytheon Co
    CHESAPEAKE VA
    ------------------------------



  • 4.  RE: Mapbasic Find succeeds with popup error

    Employee
    Posted 09-05-2023 03:00

    Hey Bryan

    I wonder if the issue comes from this statement:

    Set Map Window 3000 Layer "TRG_HST_1" Editable Off Selectable On Zoom (1,100000) Off Label Position Center Font("Arial",0,12,16776960) Pen(1,2,0) With Str$(trackId) Parallel On Visibility Off Auto Off Overlap Off

    Specifically: Str$(trackId) 

    trackId is now a Char column and you shouldn't use the Str$() function on that column type.



    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------