阅读:1458回复:1
求助:mapcontrol控件加载图层问题
<P>各位前辈,本人在初学ao,我想添加了命令在mapcontrol控件中加载一个图层,代码如下,为什么运行时vb提示"要求对象"的错误?请高人指点一二,本人不胜感谢.</P>
<P>Private Sub OpenGeoDataBaseFile(ByVal sAllFileName As String, ByVal sTableName As String)<BR> Dim pWorkspaceFactory As IWorkspaceFactory<BR> Dim pFeatureWorkspace As IFeatureWorkspace<BR> Dim pFeatureLayer As IFeatureLayer<BR> Dim pMxDocument As IMxDocument<BR> Dim pMap As IMap<BR> Dim sDir As String<BR> <BR>On Error GoTo ErrorHandler:<BR> sDir = Dir(sAllFileName)<BR> If (sDir = "") Then<BR> MsgBox ("文件不存在")<BR> Exit Sub<BR> End If<BR> <BR> <BR> 'Create a new AccessWorkspaceFactory object and open a GeoDataBaseFile<BR> Set pWorkspaceFactory = New AccessWorkspaceFactory<BR> Set pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(sAllFileName, 0)</P> <P> 'Create a new FeatureLayer and assign a Table to it<BR> Set pFeatureLayer = New FeatureLayer<BR> Set pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(sTableName)<BR> pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName</P> <P> 'Add the FeatureLayer to the focus map<BR> Set pMxDocument = Application.Document<BR> Set pMap = pMxDocument.FocusMap<BR> pMap.AddLayer pFeatureLayer<BR> Exit Sub<BR>ErrorHandler:<BR> MsgBox Err.Description<BR>End Sub</P> <P>Private Sub command1_Click()<BR> Dim pVBProject As VBProject<BR>On Error GoTo ErrorHandler:<BR> Set pVBProject = ThisDocument.VBProject<BR> <BR> OpenGeoDataBaseFile pVBProject.FileName ; "aaa.mdb", "aaa"<BR> Exit Sub<BR>ErrorHandler:<BR> MsgBox Err.Description<BR> <BR>End Sub</P> |
|
1楼#
发布于:2007-02-01 15:37
已解决
|
|