vb.net 开发mapx,从search出的features中获得对象的坐标出现问题
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
JScript
SerializableAttribute
ComVisibleAttribute(true)
public class AccessViolationException extends SystemException
备注
当非托管或不安全代码试图读写未分配或不具有访问权限的内存空间时,就会产生访问冲突。这种情况通常因为指针具有错误的值而发生。并非所有通过错误指针的读写操作都会引发访问冲突,所以访问冲突通常指示已经通过错误指针进行多次读写操作,并且内存内容可能已损坏。因此,访问冲突几乎总是指示存在严重的编程错误。在 .NET Framework 2.0 版中,AccessViolationException 清楚地标识了这些错误。
在完全由可验证托管代码组成的程序中,所有引用都有效或者为空,因而不会产生访问冲突。AccessViolationException 只在可验证托管代码与非托管代码或非安全托管代码交互时才会引发。
版本信息
此异常是 .NET Framework 2.0 版中新增的异常。在 .NET Framework 较早版本中,非托管代码或非安全托管代码中的访问冲突用托管代码中的 NullReferenceException 表示。当在可验证托管代码中取消空引用时,也会引发 NullReferenceException,这种情况的引发与数据损坏无关,且在 1.0 版或 1.1 版中无法区分这两种情况。
管理员可以允许所选择的应用程序恢复为 .NET Framework 1.1 版的行为。将下一行置于应用程序配置文件的 <runtime> 元素 节中:
复制代码
<legacyNullReferenceExceptionPolicy enabled = "1"/>
继承层次结构
System.Object
System.Exception
System.SystemException
System.AccessViolationException
线程安全
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
平台
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0
请参见
参考
AccessViolationException 成员
System 命名空间
其他资源
处理和引发异常
[解决办法]
可惜不怎么懂.net,
我以前用vb的时候都用 set ft=...
set lyr = ...