Public Function GetLinePtDate(ByVal lyr As MapXLib.Layer, ByVal v_Field As String, ByVal v_Id As String, ByRef Pts As ArrayList) As Boolean
Dim strID As String
Dim lyr As MapXLib.Layer = Nothing
Dim strCondition As String
Dim strfield As String
Dim LinePt As PointF
'Dim pt As New MapXLib.Point
Dim Ftrs As MapXLib.Features '图元集合
Dim ft As MapXLib.Feature
Ftrs = Nothing
ft = Nothing
'ReDim LinePts(0)
Dim i As Integer
strID = v_Id ' "36585102992"
strfield = v_Field ' "ID"
lyr=GetLayerObject("Rfujian_fz")
If lyr IsNot Nothing Then
strCondition = strfield & "=""" & strID & """"
'Ftrs = New MapXLib.Features
Ftrs = lyr.Search(strCondition) '莫名其妙的"尝试读取或写入受保护的内存。这通常指示其他内存已损坏。"
If Ftrs.Count > 0 Then
ft = New MapXLib.Feature '这里也可能出现
ft = Ftrs.Item(1)
For i = 1 To ft.Parts(1).Count
LinePt.X = ft.Parts(1).Item(i).X'这里也可能出现
LinePt.Y = ft.Parts(1).Item(i).Y'这里也可能出现
Pts.Add(LinePt)
Debug.Print("add success")
Next
Ftrs = Nothing
ft = Nothing
Return True
End If
End If
Return False
End Function
Public Function GetLayerObject(ByVal v_LayerName As String) As MapXLib.Layer
Dim lyr As MapXLib.Layer
Dim LayerName As String
Dim ds As MapXLib.Dataset
Dim i As Integer
Dim j As Integer
LayerName = v_LayerName '"Rfujian_xm"
i = AxMap1.Layers.Count
For j = 1 To i
If UCase(LayerName) = UCase(Trim(AxMap1.Layers.Item(j).Name)) Then
lyr = AxMap1.Layers.Item(j)
lyr.Editable = True
ds = AxMap1.DataSets.Add(MapXLib.DatasetTypeConstants.miDataSetLayer, lyr)
Return lyr
End If
Next
Return Nothing
End Function
我第一次调用基本不会出问题,如果再调用就提示"尝试读取或写入受保护的内存。这通常指示其他内存已损坏。"输出窗口提示"在 System.AccessViolationException 中第一次偶然出现的“mscorlib.dll”类型的异常",赶紧帮忙呀!!!!!
再线等!!!!
------解决方案--------------------
.NET Framework 类库
AccessViolationException 类
注意:此类在 .NET Framework 2.0 版中是新增的。
在试图读写受保护内存时引发的异常。
命名空间:System
程序集:mscorlib(在 mscorlib.dll 中)
语法
Visual Basic(声明)
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class AccessViolationException
Inherits SystemException
Visual Basic(用法)
Dim instance As AccessViolationException
C#
[SerializableAttribute]
[ComVisibleAttribute(true)]
public class AccessViolationException : SystemException
C++
[SerializableAttribute]
[ComVisibleAttribute(true)]
public ref class AccessViolationException : public SystemException
J#
/** @attribute SerializableAttribute() */
/** @attribute ComVisibleAttribute(true) */
public class AccessViolationException extends SystemException