Purpose
Returns information about the search results produced by SearchPoint() or SearchRect(). You can call this function from the MapBasic window in MapInfo Pro.
Syntax
SearchInfo( sequence_number, attribute )
sequence_number is an integer number, from 1 to the number of objects located.
attribute is a small integer code from the table below.
Return Value
String or integer, depending on attribute.
Description
After you call SearchRect() or SearchPoint() to search for map objects, call SearchInfo() to process the search results.
The sequence_number argument is an integer number, 1 or larger. The number returned by SearchPoint() or SearchRect() is the maximum value for the sequence_number.
The attribute argument must be one of the codes (from MAPBASIC.DEF) in the following table:
attribute code | ID | SearchInfo() returns: |
---|---|---|
SEARCH_INFO_TABLE | 1 | String value: the name of the table containing this object. If an object is from a Cosmetic layer, this string has the form "CosmeticN" (where N is a number, 1 or larger). |
SEARCH_INFO_ROW | 2 | Integer value: this row's rowID number. You can use this rowID number in a Fetch statement or in a Select statement's Where clause. |
Search results remain in memory until the application halts or until you perform another search. Note that search results remain in memory even after the user closes the window or the tables associated with the search; therefore, you should process search results immediately. To manually free the memory used by search results, perform a search which you know will fail (for example, search at location 0, 0).
MapInfo Pro maintains a separate set of search results for each MapBasic application that is running, plus another set of search results for MapInfo Pro itself (for commands entered through the MapBasic window).
Error Conditions
ERR_FCN_ARG_RANGE (644) error is generated if sequence_number is larger than the number of objects located.
Example
The following program creates two custom tool buttons. If the user uses the point tool, this program calls the SearchPoint() function; if the user uses the rectangle tool, the program calls the SearchRect() function. In either case, this program calls SearchInfo() to determine which object(s) the user chose.
Include "mapbasic.def"
Include "icons.def"
Declare Sub Main
Declare Sub tool_sub
Sub Main
Create ButtonPad "Searcher" As
ToolButton Calling tool_sub ID 1
Icon MI_ICON_ARROW
Cursor MI_CURSOR_ARROW
DrawMode DM_CUSTOM_POINT
HelpMsg "Click on a map location\nClick a location"
Separator
ToolButton Calling tool_sub ID 2
Icon MI_ICON_SEARCH_RECT
Cursor MI_CURSOR_FINGER_LEFT
DrawMode DM_CUSTOM_RECT
HelpMsg "Drag a rectangle in a map\nDrag a rectangle"
Width 3
Print "Searcher program now running."
Print "Choose a tool from the Searcher toolbar"
Print "and click on a map."
End Sub
Sub tool_sub
' This procedure is called whenever the user uses
' one of the custom buttons on the Searcher toolbar.
Dim x, y, x2, y2 As Float,
i, i_found, i_row_id, i_win_id As Integer,
s_table As Alias
i_win_id = FrontWindow()
If WindowInfo(i_win_id, WIN_INFO_TYPE) <> WIN_MAPPER Then
Note "This tool only works on Map windows."
Exit Sub
End If
' Determine the starting point where the user clicked.
x = CommandInfo(CMD_INFO_X)
y = CommandInfo(CMD_INFO_Y)
If CommandInfo(CMD_INFO_TOOLBTN) = 1 Then
' Then the user is using the point-mode tool.
' determine how many objects are at the chosen point.
i_found = SearchPoint(i_win_id, x, y)
Else
' The user is using the rectangle-mode tool.
' Determine what objects are within the rectangle.
x2 = CommandInfo(CMD_INFO_X2)
y2 = CommandInfo(CMD_INFO_y2)
i_found = SearchRect(i_win_id, x, y, x2, y2)
End If
If i_found = 0 Then
Beep ' No objects found where the user clicked.
Else
Print Chr$(12)
If CommandInfo(CMD_INFO_TOOLBTN) = 2 Then
Print "Rectangle: x1= " + x + ", y1= " + y
Print "x2= " + x2 + ", y2= " + y2
Else
Print "Point: x=" + x + ", y= " + y
End If
' Process the search results.
For i = 1 to i_found
' Get the name of the table containing a "hit".
s_table = SearchInfo(i, SEARCH_INFO_TABLE)
' Get the row ID number of the object that was a hit.
i_row_id = SearchInfo(i, SEARCH_INFO_ROW)
If Left$(s_table, 8) = "Cosmetic" Then
Print "Object in Cosmetic layer"
Else
' Fetch the row of the object the user clicked on.
Fetch rec i_row_id From s_table
s_table = s_table + ".col1"
Print s_table
End If
Next
End If
End Sub
See Also:
SearchPoint() function, SearchRect() function