AnsweredAssumed Answered

NullReferenceException Error when i tried to delete selected point

Question asked by fengye on Aug 24, 2015
Latest reply on Aug 25, 2015 by YLiu-esristaff

Hi there,

 

I got NullReferenceException Error when I tried to delete selected point.

 

In my code:

 

(1)  check the status of the selected point

(2) move it to the history layer

(3) delete the point from live layer

 

The whole function is shown below:

 

 

Public Sub RemovePt(ByVal lpCreatWS As IWorkspace, ByVal lpFeatureLayer As IFeatureLayer, ByVal lpHistLyrName As String, ByVal lsFldName As String, ByVal lsLayerName As String, ByVal lpFeatCursor As IFeatureCursor, ByVal lbIsHor As Boolean)
        Dim lbIsPtDead, lbIsPtNull As Boolean
        Dim lbIsHistValuesInserted As Boolean
        Dim liSuccessFulDeletedPoint As Integer
        Dim liUnSuccessFulDeletedPoint As Integer
        Dim lsPtStatus As String
        Dim lsParentVersionName As String

        Dim lpObjGenClass As New clsGeneralClass
        Dim lpVerFC As IFeatureClass
        Dim lpObjSDEUtils As New clsSdeUtils
        Dim lpHistFeatureClass As IFeatureClass
        Dim lpVerFeat As IFeature
        Dim lpHistFeat As IFeature
        Dim lpFeature As IFeature
        Dim lpObjGeneralClass As New clsGeneralClass
        Dim lpCreatVer As IVersion
        Dim lpVersionEdit As IVersionEdit
        Dim lpWorkSpaceEdit As IWorkspaceEdit

        'Get the Deafault Version
        lpCreatVer = lpCreatWS
        lpCreatVer.RefreshVersion()

        'get the Version Edit
        lpVersionEdit = lpCreatWS

        'Get the WS to be edited
        lpWorkSpaceEdit = lpCreatWS

        Try

            'Iterate through the selected features in the Layer
            lpFeature = lpFeatCursor.NextFeature

            'Delcare the new Collection Object
            gcolPtStatus = New Collection

            'Start Editing Operation
            lpWorkSpaceEdit.StartEditing(True)

            Do Until lpFeature Is Nothing
                Call CheckPtStatus(lpFeature, lbIsPtDead, lbIsPtNull)

                'Make the Status DEAD

                lpVerFC = lpObjSDEUtils.GetFeatureClass(lpCreatWS, lsLayerName)
                             
                lpVerFeat = lpVerFC.GetFeature(lpFeature.OID)                 ' ==================== I can get the lpFeature.OID, but get error this line

 

                'If Point Stauts is Live
                If lbIsPtDead = False And lbIsPtNull = False Then
          
                    'Check if Point History FeatureLayer is not Nothing
                    If gpHistoryClass Is Nothing Then
                        'If Nothing,Get the Pt History layer
                        lpHistFeatureClass = lpObjSDEUtils.GetFeatureClass(lpCreatWS, lpHistLyrName)
                    End If
                   
                    'Create a new History Class feature
                    lpHistFeat = lpHistFeatureClass.CreateFeature
                    lpHistFeat.Shape = lpFeature.Shape
                   
                    'Insert the history feature values
                    lbIsHistValuesInserted = lpObjGeneralClass.InsertValues(lpFeature, lpHistFeat)
                  
                    If lbIsHistValuesInserted = False Then
                        'Donot save the editing operations
                        lpWorkSpaceEdit.StopEditing(False)

                        'Make the Collection Nothing
                        gcolPtStatus = Nothing
                        Exit Sub
                    End If

                    'Update Point Status
                    Call UpdatePtStatus(lpVerFeat)

                    'Frame the Control Point Status
                    lsPtStatus = lpVerFeat.Value(lpVerFeat.Fields.FindField(lsFldName)) & "    " & ": Deleted Successfully"

                    'Get the Count of Successfully Deleted Pt's
                    liSuccessFulDeletedPt = liSuccessFulDeletedPt + 1
                ElseIf lbIsPtDead = True And lbIsPtNull = False Then
                    'Frame the Control Point Status
                    lsPtStatus = lpVerFeat.Value(lpVerFeat.Fields.FindField(lsFldName)) & "    " & ": Error in Deleting (Already Dead)"
                    'Get the Count of UnSuccessfull Deleted Pt's
                    liUnSuccessFulDeletedtP = liUnSuccessFulDeletedPt + 1
                ElseIf lbIsPtDead = False And lbIsPtNull = True Then
                    'Frame the Control Point Status
                    lsPtStatus = lpVerFeat.Value(lpVerFeat.Fields.FindField(lsFldName)) & "    " & ": Error in Deleting (Status Null)"
                    'Get the Count of UnSuccessfull Deleted Pt's
                    liUnSuccessFulDeletedPt = liUnSuccessFulDeletedPt + 1
                End If

                'Add to the Collection
                gcolPtStatus.Add(lsPointStatus)

                'Iterate through the next feature
                lpFeature = lpFeatCursor.NextFeature
            Loop

            'Chech if the Created version has parent
            If lpCreatVer.HasParent Then
                lsParentVersionName = lpCreatVer.VersionInfo.Parent.VersionName
            Else
                MsgBox("You can only reconcile a version that has a parent.")
            End If

            'Get the SDE Default's Latest Version
            'lpVersionEdit.Reconcile(lsParentVersionName)
            lpCreatVer.RefreshVersion()
            lpVersionEdit.Reconcile(lsParentVersionName)
            If lpVersionEdit.CanPost Then
                lpVersionEdit.Post(lsParentVersionName)
            End If

            'StopEditing Operation
            lpWorkSpaceEdit.StopEditing(True)
            lpVersionEdit.RefreshVersion()
            'Display the Log File
            WriteLogFile(liSuccessFulDeletedPt, liUnSuccessFulDeletedPt, lbIsHor)
            'Refresh the Version

 

        Catch ex As Exception
            'On Error, Display Error Message
            MsgBox("Error occured in remove control point(s) ")

            'Donot save the editing operations
            lpWorkSpaceEdit.AbortEditOperation()
            lpWorkSpaceEdit.StopEditing(False)

            'Make the Collection Nothing
            gcolPtStatus = Nothing
        Finally
            'Release the Objects
            lpVerFC = Nothing
            lpCreatVer = Nothing
            lpVersionEdit = Nothing
            lpFeature = Nothing
            lpHistFeat = Nothing
            lpHistFeatureClass = Nothing
            lpFeatCursor = Nothing
            lpObjSDEUtils = Nothing
            lpObjGenClass = Nothing
            lpWorkSpaceEdit = Nothing

            AutoReleaseCom(lpVerFC)
            AutoReleaseCom(lpCreatVer)
            AutoReleaseCom(lpVersionEdit)
            AutoReleaseCom(lpFeature)
            AutoReleaseCom(lpHistFeat)
            AutoReleaseCom(lpHistFeatureClass)
            AutoReleaseCom(lpFeatCursor)
            AutoReleaseCom(lpWorkSpaceEdit)
            AutoReleaseCom(lpObjSDEUtils)
            AutoReleaseCom(lpObjGeneralClass)
        End Try

    End Sub

thing may cause the error? thanks

Any

Outcomes