coverage
路人甲
路人甲
  • 注册日期2008-07-03
  • 发帖数14
  • QQ
  • 铜币180枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1710回复:4

刚学AO开发遇到些问题,恳请帮忙解答!

楼主#
更多 发布于:2008-07-30 09:12
<P>我在按照如下的实例进行操作时,遇到了一些问题,恳请各位能指点迷津。</P>
<P>使用VB创建一个COM组件 <BR>1、创建一个ActiveX DLL 工程 <BR>启动VB,在创建新工程的时候选择“ActiveX DLL”类型。<BR>修改Class1类模块名称为“AdjacentTool”。<BR>修改“Project1”工程名称为“Tutorial”。<BR>导入“ArcID”模块。<BR>保存类“AdjacentTool”为“Tutorial_ AdjacentTool.cls”文件。保存工程为“Tutorial.vbp”文件。<BR>2、引用对象库 <BR>在VB的“Project”菜单,选择“References”菜单条。<BR>在“References”对话框,选择ArcMap Object Library 和 ESRI Object Library。<BR>(如果在条目中没有该两项,则查找引用EsriMx.olb和EsriCore.olb)单击 “OK”按钮。 <BR>3、实现所需的接口 <BR>在“AdjacentTool”类模块代码窗体顶部添加如下代码:<BR>Option Explicit<BR>Implements ICommand<BR>Implements ITool<BR>Dim pApp As esriMx.Application 'ArcMap app<BR>Dim pDoc As ImxDocument<BR>在代码窗口的左边组合框中选择“Icommand”条目。在代码窗口的右边组合框中选择每一个方法或属性去创建空的过程。对“Itool”条目重复以上两项,创建每一个方法或属性的空过程。 <BR>4、增加工具的区别代码 <BR>Private Property Get ICommand_Category() As String<BR>'Category属性表现为在“Customize”对话框的“Commands”页面的左边列表中。<BR>    ICommand_Category = "Tutorial"<BR>End Property<BR>Private Property Get ICommand_Caption() As String<BR>'Category属性表现为在“Customize”对话框的“Commands”页面的右边列表中。<BR>    ICommand_Caption = "AdjacentTool"<BR>End Property<BR>Private Property Get ICommand_Name() As String<BR>    ICommand_Name = "Tutorial_AdjacentTool"<BR>End Property<BR>5、增加工具的描述代码 <BR>Private Property Get ICommand_Message() As String<BR>  '鼠标移动经过时在状态条上显示的信息。<BR>     ICommand_Message = "Selects features " ; "Adjacent to the feature you click on"<BR>End Property<BR>Private Property Get ICommand_Tooltip() As String<BR> '鼠标移动经过时显示的信息。<BR>    ICommand_Tooltip = "Select adjacent features"<BR>End Property<BR>6、增加工具的可用性代码 <BR>Private Sub ICommand_OnCreate(ByVal hook As Object)<BR>     Set pApp = hook<BR>     Set pDoc = pApp.Document<BR>End Sub<BR>Private Property Get ICommand_Enabled() As Boolean<BR>    With pDoc.FocusMap<BR>        If .LayerCount > 0 Then<BR>            ICommand_Enabled = True<BR>        ElseIf .LayerCount = 0 Then<BR>            ICommand_Enabled = False<BR>        End If<BR>    End With<BR>End Property<BR>Private Function ITool_Deactivate() As Boolean<BR> ’其他按钮按下是是否失效,缺省为False<BR>    ITool_Deactivate = True<BR>End Function<BR>7、增加工具的功能实现代码 <BR>Private Sub ITool_OnMouseDown(ByVal Button As Long, ByVal Shift As Long, ByVal X As Long, ByVal Y As Long)<BR>     Dim pScreenDisp As IScreenDisplay<BR>     Dim pDt As IDisplayTransformation<BR>     Dim pPt As IPoint<BR>     Dim pMap As IMap<BR>     Dim pLayer As IFeatureLayer<BR>     Dim pSelEnv As ISelectionEnvironment<BR>     Dim pSelection As ISelection<BR>     Dim pEnumFeat As IEnumFeature<BR>     Dim pFeature As IFeature<BR>     Dim pFeatureCursor As IFeatureCursor<BR>     Dim pSpatialFilter As ISpatialFilter<BR>     Dim pFeatureSelection As IFeatureSelection<BR>     Dim pFillSymbol As ISimpleFillSymbol<BR>     Dim pColor As IRgbColor<BR>     Dim psym As ISymbol<BR>     '把屏幕坐标点转换成地图坐标点<BR>     Set pScreenDisp = pDoc.ActiveView.ScreenDisplay<BR>     Set pDt = pScreenDisp.DisplayTransformation<BR>     'get the MouseDown location in map units<BR>     Set pPt = pDt.ToMapPoint(X, Y)<BR>     '引用一个图层<BR>     'the tutorial expects the first layer to<BR>     'serve as the target<BR>     Set pMap = pDoc.ActiveView.FocusMap<BR>     Set pLayer = pMap.Layer(0)<BR>     pLayer.Selectable = True<BR>'定义空间过滤条件<BR>     'create a SpatialFilter to be used in<BR>     'a point in polygon selection<BR>     Set pSpatialFilter = New SpatialFilter<BR>     With pSpatialFilter<BR>      Set .Geometry = pPt<BR>      .GeometryField = _<BR>      pLayer.FeatureClass.ShapeFieldName<BR>      .SpatialRel = esriSpatialRelWithin<BR>     End With<BR>  ‘'空间查询<BR>     Set pFeatureCursor = _<BR>     pLayer.Search(pSpatialFilter, False)<BR>     'pFeature is a polygon feature<BR>     Set pFeature = pFeatureCursor.NextFeature<BR>     <BR>     'create a SpatialFilter to be used in the<BR>     'search for polygons adjacent to pFeature<BR>     Set pSpatialFilter = New SpatialFilter<BR>     With pSpatialFilter<BR>      Set .Geometry = pFeature.Shape<BR>      .GeometryField = _<BR>      pLayer.FeatureClass.ShapeFieldName<BR>      .SpatialRel = esriSpatialRelTouches<BR>     End With<BR>     Set pFeatureSelection = pLayer 'QI<BR>     ‘'空间选择<BR>     pFeatureSelection.SelectFeatures _<BR>     pSpatialFilter, esriSelectionResultNew, False<BR>     pFeatureSelection.SetSelectionSymbol = True<BR>‘'定义颜色及符号<BR>     Set pColor = New RgbColor<BR>     pColor.RGB = vbRed<BR>     Set pFillSymbol = New SimpleFillSymbol<BR>     pFillSymbol.Color = pColor<BR>     pFillSymbol.Style = esriSFSSolid<BR>     '显示选择结果<BR>     Set psym = pFillSymbol 'QI<BR>     Set pFeatureSelection.SelectionSymbol = psym<BR>     Dim pitem As ICommandItem<BR>     pDoc.ActiveView.Refresh<BR>     '使用内建命令统计选择集合<BR>     'finish by displaying<BR>     'statistics for the adjacent features<BR>     'ArcID is a VB module that was exported from<BR>     'ArcMap<BR>     Set pitem = pApp.Document.CommandBars _<BR>     .Find(ArcID.Query_SelectionStatistics)<BR>     pitem.Execute<BR>End Sub<BR>8、编译成DLL库 <BR>在VB的“Project”菜单中,选择“Tutorial Properties”,然后选择“Component”页面。选择“Binary Compatibility”选项。单击“OK”。保存工程。在“File”菜单中,选择“Make Tutorial.dll”。  <BR>9、使用ArcMap注册该组件库 <BR>启动ArcMap在“Tools”菜单中选择“Customize”。点击“Customize”对话框中的“Add from file”按钮。双击“Tutorial.dll”。单击“OK”按钮。可以看出在“Customize”对话框的“Commands”页面的左边增加了一个名为“Tutorial”的条目。在该条目中有一个“AadjacentTool”的命令。<BR>10、把组件添加到文档并使用。 <BR>把上面注册的“AdjacentTool”命令拖放到一个工具条上。使用该工具条,观察工具效果。(使用USA的STATES数据作为例子数据。)  </P>
<P><FONT color=#ff0000>遇到了如下一些问题:</FONT></P>
<P><FONT color=#ff3300>1、在第一条中第4行“导入ArcID模块”是如何实现的?</FONT></P>
<P><FONT color=#ff3300>2、我将代码在VB程序dll界面下输入完成后,总是在该行(<FONT color=#000000>Dim pApp As esriMx.Application 'ArcMap app</FONT>)显示用户定义类型未定义,而且很多次我用到Application时都有这种显示。</FONT></P>
<P><FONT color=#ff3300>3、第8条编译成DLL库,按照提示操作时,我选择“二进制兼容”时,提示我不能二进制兼容。</FONT></P>
<P><FONT color=#ff3300>是不是我的VB有问题,是需要一些引用,但是我的引用里面关于ESRI的我全部选定了,希望各位朋友帮忙指导一下,我现在正在学习AO开发,还没入门,恳请帮助!</FONT></P>
<P><FONT color=#ff3300>小弟不胜感激!!</FONT></P><img src="images/post/smile/dvbbs/em02.gif" />
喜欢0 评分0
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
1楼#
发布于:2008-07-30 10:58
<P><FONT color=#ff3300>ArcID在默认的mxt文档里有;</FONT></P>
<P>Application只在arcmap和arccatalog,arcscene里有效;</P>
举报 回复(0) 喜欢(0)     评分
coverage
路人甲
路人甲
  • 注册日期2008-07-03
  • 发帖数14
  • QQ
  • 铜币180枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2008-07-30 11:36
<P>非常感谢您的回复!</P>
<P>但我还是不太明白,我是按照它上面的提示一步步操作的,为什么没看到ArcID模块,但能在ArcMap内部的宏里面看到,我不太明白他这一句“导入ArcID模块”是什么意思。</P>
<P>Application在这儿是无效的吗?劳烦给解释的详细点!</P><img src="images/post/smile/dvbbs/em02.gif" /><img src="images/post/smile/dvbbs/em01.gif" />
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
3楼#
发布于:2008-07-30 13:17
<P>上面说错,Application在你的程序里是有效的,但是代码是8.x版本的,所以在9.x中已经变化了</P>
<P>”Dim pApp As esriMx.Application“改为 "<STRONG>Dim pApp As Application</STRONG>" . </P>
<P>你可以在下面的连接里找到8.x和9.x的一些不同: http://edndoc.esri.com/arcobjects/9.0/ </P>
[此贴子已经被作者于2008-7-30 13:18:00编辑过]
举报 回复(0) 喜欢(0)     评分
coverage
路人甲
路人甲
  • 注册日期2008-07-03
  • 发帖数14
  • QQ
  • 铜币180枚
  • 威望0点
  • 贡献值0点
  • 银元0个
4楼#
发布于:2008-07-30 13:36
谢谢,我仔细看一下,非常感谢!!<img src="images/post/smile/dvbbs/em02.gif" /><img src="images/post/smile/dvbbs/em01.gif" />
举报 回复(0) 喜欢(0)     评分
游客

返回顶部