I have an application to Track Vehicles on the Map. We Draw Shapes with the mouse on the Map to divide the city into zones. The vehicles are created as push pins in a specific DataSet.
When we Query a Shape, the results are returned Ok. But after peforming the QueryShape several hundred times, MapPoint Crashs.
I am attaching some code for review. If this code is called from a for loop statement the error will appear almost within 3-4 minutes:
Public Function MapGenerateVehicleInAZoneList(lngZoneNumber As Long) As Boolean
Dim TZoneFeature As ZONE_FEATURE
Dim blnOk As Boolean
Dim strFunctionName As String
strFunctionName = vbNewLine & "MapGenerateVehicleInAZoneList"
On Error GoTo Err_MapGenerateVehicleInAZoneList
blnOk = False
If ZDReadZoneRecordFromArray(lngZoneNumber, TZoneFeature) = True Then
blnOk = MapGenerateVehiclesWithinAFeatureList(TZoneFeature .oShape)
End If
Exit_MapGenerateVehicleInAZoneList:
MapGenerateVehicleInAZoneList = blnOk
Exit Function
Err_MapGenerateVehicleInAZoneList:
MsgBox Err.Description & strFunctionName
Resume Exit_MapGenerateVehicleInAZoneList
End Function
Public Function MapGenerateVehiclesWithinAFeatureList(oShape As MapPointCtl.Shape) As Boolean
Dim TTempVehicleRecord As VEHICALE_RECORD
Dim intNumVehiclesFound As Integer
Dim intRecordNumber As Integer
Dim blnOk As Boolean
Dim objRecords As MapPointCtl.Recordset
Dim strFunctionName As String
strFunctionName = vbNewLine & "MapGenerateVehiclesWithinAFeatureList"
On Error GoTo Err_MapGenerateVehiclesWithinAFeatureList
blnOk = False
intNumVehiclesFound = 0
ReDim TVehicleListReported(1)
'THIS LINE CAUSES THE PROBLEM. AFTER FIXED NUMBER OF CALLS
Set objRecords = frmMain.Map1.ActiveMap.DataSets(STR_VEHICLES_PLOT_ DATA_SET).QueryShape(oShape)
If objRecords.BOF = False Then
objRecords.MoveFirst
' Add results of search to results list box control
Do While Not objRecords.EOF
If objRecords.Pushpin.Name <> "0" Then
If CRGetVehicleRecordNumber(objRecords.Pushpin.Name, intRecordNumber, False) = True Then
Call CRReadRecord(intRecordNumber, TTempVehicleRecord)
intNumVehiclesFound = intNumVehiclesFound + 1
ReDim Preserve TVehicleListReported(intNumVehiclesFound)
TVehicleListReported(intNumVehiclesFound).strVehic leNumber = CStr(objRecords.Pushpin.Name)
TVehicleListReported(intNumVehiclesFound).strLastT imeUpdated = RTrim$(TTempVehicleRecord.strLastTimeUpdated)
End If
End If
objRecords.MoveNext
Loop
End If
Call CMNUpdateNumOfVehiclesReported(intNumVehiclesFound )
blnOk = True
Exit_MapGenerateVehiclesWithinAFeatureList:
MapGenerateVehiclesWithinAFeatureList = blnOk
Exit Function
Err_MapGenerateVehiclesWithinAFeatureList:
MsgBox Err.Description & strFunctionName
Resume Exit_MapGenerateVehiclesWithinAFeatureList
End Function
Please advise