IObjectLoader.LoadObjects Method
Loads an object into an existing object class. 有幾點要注意的是:
1)該方法有返回值pEnumInvalidObject,如果applyValidation變量是false,將返回空值,如果為True,將返回 invalid features.
2) IQueryFilter::SubFields必須與IObjectLoader::OutputFields相匹配
3)相應字段集 IsNullable and Editable參數要對應,否則會出錯.
Function LoadObjects(
ByVal Editor As IEditor, _
ByVal inputTable As ITable, _
ByVal inputQueryFilter As IQueryFilter, _
ByVal outputTable As ITable, _
ByVal OutputFields As IFields, _
ByVal setSubType As Boolean, _
ByVal subTypeCode As Long, _
ByVal snapToFeatures As Boolean, _
ByVal applyValidation As Boolean, _
ByVal flushInterval As Long, _
ppInvalidObjectEnum As IEnumInvalidObject _
) As ISelectionSet
' Syntax of LoadObjects
ByVal Editor As IEditor, _
ByVal inputTable As ITable, _
ByVal inputQueryFilter As IQueryFilter, _
ByVal outputTable As ITable, _
ByVal OutputFields As IFields, _
ByVal setSubType As Boolean, _
ByVal subTypeCode As Long, _
ByVal snapToFeatures As Boolean, _
ByVal applyValidation As Boolean, _
ByVal flushInterval As Long, _
ppInvalidObjectEnum As IEnumInvalidObject _
) As ISelectionSet
' Syntax of LoadObjects
Public Sub Command1_Click()
On Error GoTo EH
' This sample loads an info file into personal geodatabase
'----------------------------------------------------
' Set up the output feature class, i.e. the empty GDBTable that exists
Dim pWSFact As IWorkspaceFactory
Dim pFeatWS As IFeatureWorkspace
Dim pFeatDS As IFeatureDataset
Dim pFields As IFields
Dim pField As IField
Set pWSFact = New AccessWorkspaceFactory
'Open FeatureWorkspace
Set pFeatWS = pWSFact.OpenFromFile("D:\data\World\tables\tabtest.mdb", 0)
Dim pGDBTable As ITable
Set pGDBTable = pFeatWS.OpenTable("demog")
'----------------------------------------------------
' Set up the input feature classe, i.e. the Info Table as SourceFullName
Dim pInFClass As IFeatureClass
Dim infoWSFact As IWorkspaceFactory
Dim infoFeatWS As IFeatureWorkspace
Set infoWSFact = New ArcInfoWorkspaceFactory
'Open FeatureWorkspace
Set infoFeatWS = infoWSFact.OpenFromFile("D:\data\World\tables", 0)
Dim infoTable As ITable
Dim pIDataset As IDataset
Set infoTable = infoFeatWS.OpenTable("demog")
'---------------------------------------------
' Set up query filter for incoming table
Dim pQueryFilter As IQueryFilter
Set pQueryFilter = New QueryFilter
Dim sInFieldList As String
sInFieldList = pGDBTable.Fields.Field(0).Name
For i = 1 To (pGDBTable.Fields.FieldCount - 1)
sInFieldList = sInFieldList + "," + pGDBTable.Fields.Field(i).Name
Next i
pQueryFilter.SubFields = sInFieldList
'----------------------------------------------------
' Set up the fields for OutputFields
Dim pOutFields As IFields
Set pOutFields = pGDBTable.Fields
'----------------------------------------------------
' Set up the ObjectLoader and run LoadObjects
Dim pObjectLoader As IObjectLoader
Set pObjectLoader = New ObjectLoader
Dim pEnumInvalidObject As IEnumInvalidObject
pObjectLoader.LoadObjects Nothing, infoTable, Nothing, pGDBTable, pOutFields, False, 0, False, False, 20, pEnumInvalidObject
Dim pInvalidObject As IInvalidObjectInfo
Set pInvalidObject = pEnumInvalidObject.Next
If Not pInvalidObject Is Nothing Then
MsgBox "Some or all features did not load"
End If
Exit Sub
EH:
MsgBox Err.Description, vbInformation, "Object Loader Example"
End Sub
On Error GoTo EH
' This sample loads an info file into personal geodatabase
'----------------------------------------------------
' Set up the output feature class, i.e. the empty GDBTable that exists
Dim pWSFact As IWorkspaceFactory
Dim pFeatWS As IFeatureWorkspace
Dim pFeatDS As IFeatureDataset
Dim pFields As IFields
Dim pField As IField
Set pWSFact = New AccessWorkspaceFactory
'Open FeatureWorkspace
Set pFeatWS = pWSFact.OpenFromFile("D:\data\World\tables\tabtest.mdb", 0)
Dim pGDBTable As ITable
Set pGDBTable = pFeatWS.OpenTable("demog")
'----------------------------------------------------
' Set up the input feature classe, i.e. the Info Table as SourceFullName
Dim pInFClass As IFeatureClass
Dim infoWSFact As IWorkspaceFactory
Dim infoFeatWS As IFeatureWorkspace
Set infoWSFact = New ArcInfoWorkspaceFactory
'Open FeatureWorkspace
Set infoFeatWS = infoWSFact.OpenFromFile("D:\data\World\tables", 0)
Dim infoTable As ITable
Dim pIDataset As IDataset
Set infoTable = infoFeatWS.OpenTable("demog")
'---------------------------------------------
' Set up query filter for incoming table
Dim pQueryFilter As IQueryFilter
Set pQueryFilter = New QueryFilter
Dim sInFieldList As String
sInFieldList = pGDBTable.Fields.Field(0).Name
For i = 1 To (pGDBTable.Fields.FieldCount - 1)
sInFieldList = sInFieldList + "," + pGDBTable.Fields.Field(i).Name
Next i
pQueryFilter.SubFields = sInFieldList
'----------------------------------------------------
' Set up the fields for OutputFields
Dim pOutFields As IFields
Set pOutFields = pGDBTable.Fields
'----------------------------------------------------
' Set up the ObjectLoader and run LoadObjects
Dim pObjectLoader As IObjectLoader
Set pObjectLoader = New ObjectLoader
Dim pEnumInvalidObject As IEnumInvalidObject
pObjectLoader.LoadObjects Nothing, infoTable, Nothing, pGDBTable, pOutFields, False, 0, False, False, 20, pEnumInvalidObject
Dim pInvalidObject As IInvalidObjectInfo
Set pInvalidObject = pEnumInvalidObject.Next
If Not pInvalidObject Is Nothing Then
MsgBox "Some or all features did not load"
End If
Exit Sub
EH:
MsgBox Err.Description, vbInformation, "Object Loader Example"
End Sub
-----------------------------------------------------------
佛对我说:你心里有尘。我用力的拭擦。