private IEnumerator getSortedList(string mField, ILayer mLayer, string whereclause) { IQueryFilter mQFilter = new QueryFilterClass(); mQFilter.WhereClause = whereclause; IEnumerator mEnumstreets = null; if (mLayer != null) { IFeatureLayer mFeatureLayer = (IFeatureLayer)mLayer; IFeatureClass pFeatureClass = mFeatureLayer.FeatureClass; if (pFeatureClass != null) { ITable pTable = (ITable)pFeatureClass; IFeatureCursor pCursor = pFeatureClass.Search(mQFilter, true); ITableSort mTableSort = new TableSortClass(); mTableSort.Table = pTable; mTableSort.Fields = mField; mTableSort.set_Ascending(mField, true); mTableSort.QueryFilter = mQFilter; mTableSort.Sort(null); IDataStatistics mDataStats = new DataStatisticsClass(); mDataStats.Cursor = mTableSort.Rows; mDataStats.Field = mField; mEnumstreets = mDataStats.UniqueValues; pCursor = null; } } return mEnumstreets; }
Solved! Go to Solution.
Armin,
I'm curious, how did you determine it was the IDataStatistics interface that was causing you problems, you say it runs OK then crashes, what made you decide it was that and not something else? I only ask as I am having a 10.1 addin I am creating crashing with a heap corruption error at seemingly random times. It's such a catastrophic error that none of my error-trapping catches it, ArcMap simply bombs out to Windows.
Duncan
Imports ESRI.ArcGIS.Geodatabase Public Interface IDataStatiticsECL WriteOnly Property Cursor() As ESRI.ArcGIS.Geodatabase.ICursor Property Field() As String ReadOnly Property UniqueValues() As System.Collections.IEnumerator End Interface Public Class DataStatisticsClassECL Implements IDataStatiticsECL Private m_Cur As ESRI.ArcGIS.Geodatabase.ICursor Public WriteOnly Property Cursor As ESRI.ArcGIS.Geodatabase.ICursor Implements IDataStatiticsECL.Cursor Set(value As ESRI.ArcGIS.Geodatabase.ICursor) m_Cur = value End Set End Property Private m_Field As String Public Property Field As String Implements IDataStatiticsECL.Field Get Return m_Field End Get Set(value As String) m_Field = value End Set End Property Public ReadOnly Property UniqueValues As System.Collections.IEnumerator Implements IDataStatiticsECL.UniqueValues Get Dim row As Row = CType(m_Cur.NextRow(), Row) Dim dic As New SortedList(Of Object, String) Dim iFeild = row.Fields.FindField(m_Field) 'loop through the data and get the unique values Do Until row Is Nothing If dic.ContainsKey(row.Value(iFeild)) = False Then dic.Add(row.Value(iFeild), "") End If row = CType(m_Cur.NextRow(), Row) Loop Dim arr(dic.Count - 1) As Object Dim arrInd As Integer dic.Keys.CopyTo(arr, arrInd) Dim n As New ValuesEnum(arr) Return n End Get End Property Private Class ValuesEnum Implements IEnumerator Private ReadOnly m_Values() As Object Private m_Cur As Integer Public Sub New(ByVal lst() As Object) m_Values = lst m_Cur = -1 End Sub Public ReadOnly Property Current() Implements IEnumerator.Current Get If m_Cur >= m_Values.Length Then Return Nothing End If Return m_Values(m_Cur) End Get End Property Public Sub Reset() Implements IEnumerator.Reset m_Cur = -1 End Sub Public Function Movenext() As Boolean Implements IEnumerator.MoveNext m_Cur = m_Cur + 1 If m_Cur < m_Values.Length Then Return True Else Return False End If End Function End Class End Class
Imports ESRI.ArcGIS.Geodatabase Public Interface IDataStatisticsECL WriteOnly Property Cursor() As ESRI.ArcGIS.Geodatabase.ICursor Property Field() As String ReadOnly Property UniqueValues() As System.Collections.IEnumerator ReadOnly Property UniqueValueCount() As Integer End Interface Public Class DataStatisticsClassECL Implements IDataStatisticsECL Private m_Cur As ESRI.ArcGIS.Geodatabase.ICursor Public WriteOnly Property Cursor As ESRI.ArcGIS.Geodatabase.ICursor Implements IDataStatisticsECL.Cursor Set(ByVal value As ESRI.ArcGIS.Geodatabase.ICursor) m_Cur = value End Set End Property Private m_Field As String = "" Public Property Field As String Implements IDataStatisticsECL.Field Get Return m_Field End Get Set(ByVal value As String) m_Field = value End Set End Property Public ReadOnly Property UniqueValues As System.Collections.IEnumerator Implements IDataStatisticsECL.UniqueValues Get Dim row As Row = CType(m_Cur.NextRow(), Row) Dim dic As New SortedList(Of Object, String) Dim iFeild = row.Fields.FindField(m_Field) 'loop through the data and get the unique values Do Until row Is Nothing If dic.ContainsKey(row.Value(iFeild)) = False Then dic.Add(row.Value(iFeild), "") End If row = CType(m_Cur.NextRow(), Row) Loop Dim arr(dic.Count - 1) As Object Dim arrInd As Integer dic.Keys.CopyTo(arr, arrInd) m_UniqueValueCount = arr.Length Dim n As New ValuesEnum(arr) Return n End Get End Property Private m_UniqueValueCount As Integer = 0 Public ReadOnly Property UniqueValueCount As Integer Implements IDataStatisticsECL.UniqueValueCount Get Return m_UniqueValueCount End Get End Property Private Class ValuesEnum Implements IEnumerator Private ReadOnly m_Values() As Object Private m_Cur As Integer Public Sub New(ByVal lst() As Object) m_Values = lst m_Cur = -1 End Sub Public ReadOnly Property Current() Implements IEnumerator.Current Get If m_Cur >= m_Values.Length Then Return Nothing End If Return m_Values(m_Cur) End Get End Property Public Sub Reset() Implements IEnumerator.Reset m_Cur = -1 End Sub Public Function Movenext() As Boolean Implements IEnumerator.MoveNext m_Cur = m_Cur + 1 If m_Cur < m_Values.Length Then Return True Else Return False End If End Function End Class End Class
Public ReadOnly Property UniqueValues As System.Collections.IEnumerator Implements IDataStatisticsECL.UniqueValues Get If m_Cur Is Nothing Then m_UniqueValueCount = 0 Dim arra(-1) As Object Dim noCursor1 As New ValuesEnum(arra) Return noCursor1 End If Dim row As Row = CType(m_Cur.NextRow(), Row) If row Is Nothing Then m_UniqueValueCount = 0 Dim arra(-1) As Object Dim noRow2 As New ValuesEnum(arra) Return noRow2 End If Dim dic As New SortedList(Of Object, String) Dim iFeild = row.Fields.FindField(m_Field) 'loop through the data and get the unique values Do Until row Is Nothing If dic.ContainsKey(row.Value(iFeild)) = False Then dic.Add(row.Value(iFeild), "") End If row = CType(m_Cur.NextRow(), Row) Loop Dim arr(dic.Count - 1) As Object Dim arrInd As Integer dic.Keys.CopyTo(arr, arrInd) m_UniqueValueCount = arr.Length Dim n As New ValuesEnum(arr) Return n End Get End Property