pWorkSpaceEdit.StartEditing True
pWorkSpaceEdit.StartEditOperation
*********************************
pWorkSpaceEdit.StopEditing True
pWorkSpaceEdit.StopEditOperation
//编辑的时候才需要
Private Sub CommandButton1_Click()
Dim PolyCount As Integer
PolyCount = Val(TextBox1.Text)
Dim i As Integer
Dim pMxDoc As IMxDocument
Set pMxDoc = Application.Document
Dim pMap As IMap
Set pMap = pMxDoc.FocusMap
Dim pActiveView As IActiveView
Set pActiveView = pMxDoc.FocusMap
Dim pFeaturelayer As IFeatureLayer
Set pFeaturelayer = pMap.Layer(0)
Dim pFeatureClass As IFeatureClass
Set pFeatureClass = pFeaturelayer.FeatureClass
Dim pDataSet As IDataset
Set pDataSet = pFeatureClass
Dim pWorkSpace As IWorkspace
Set pWorkSpace = pDataSet.Workspace
Dim pWorkSpaceEdit As IWorkspaceEdit
Set pWorkSpaceEdit = pWorkSpace
pWorkSpaceEdit.StartEditing True
pWorkSpaceEdit.StartEditOperation
For i = 0 To PolyCount - 1
Dim pFeature As IFeature
Set pFeature = pFeatureClass.CreateFeature
Dim pPoint As IPoint
Set pPoint = New Point
pPoint.PutCoords 10000000000000# * Rnd, 10000000000000# * Rnd
Set pFeature.Shape = pPoint
Dim pFields As IFields
Set pFields = pFeatureClass.Fields
Dim idx As Integer
idx = pFields.FindField("Name")
pFeature.Value(idx) = "武汉" & i
pFeature.Store
Next i
pActiveView.Refresh
pWorkSpaceEdit.StopEditing True
End Sub
‘=======================================
Private Sub CommandButton1_Click()
Dim PolyCount As Integer
PolyCount = Val(TextBox1.Text)
Dim i As Integer
Dim pMxDoc As IMxDocument
Set pMxDoc = Application.Document
Dim pMap As IMap
Set pMap = pMxDoc.FocusMap
Dim pActiveView As IActiveView
Set pActiveView = pMxDoc.FocusMap
Dim pFeaturelayer As IFeatureLayer
Set pFeaturelayer = pMap.Layer(0)
Dim pFeatureClass As IFeatureClass
Set pFeatureClass = pFeaturelayer.FeatureClass
Dim pDataSet As IDataset
Set pDataSet = pFeatureClass
Dim pWorkSpace As IWorkspace
Set pWorkSpace = pDataSet.Workspace
Dim pWorkSpaceEdit As IWorkspaceEdit
Set pWorkSpaceEdit = pWorkSpace
pWorkSpaceEdit.StartEditing True
pWorkSpaceEdit.StartEditOperation
For i = 0 To PolyCount - 1
Dim pFeature As IFeature
Set pFeature = pFeatureClass.CreateFeature
Dim pPointCollection4 As IPointCollection4
Set pPointCollection4 = New Polygon
Dim pPolygon As IPolygon
Set pPolygon = pPointCollection4
Dim pPoint As IPoint
Set pPoint = New Point
pPoint.PutCoords 571 * Rnd - 450, 351 * Rnd - 90
pPointCollection4.AddPoint pPoint
Set pPoint = New Point
pPoint.PutCoords 571 * Rnd - 450, 351 * Rnd - 90
pPointCollection4.AddPoint pPoint
Set pPoint = New Point
pPoint.PutCoords 571 * Rnd - 450, 351 * Rnd - 90
pPointCollection4.AddPoint pPoint
Set pFeature.Shape = pPolygon
Dim pFields As IFields
Set pFields = pFeatureClass.Fields
Dim idx As Integer
idx = pFields.FindField("Name")
pFeature.Value(idx) = "武汉" & i
pFeature.Store
Next i
pActiveView.Refresh
pWorkSpaceEdit.StopEditing True
End Sub