【问题标题】:C# did you intend to invoke methodC# 你是否打算调用方法
【发布时间】:2012-08-08 14:18:55
【问题描述】:

我正在尝试转换为 C# 的 Vba 代码。我已经非常接近了,但我可以弄清楚为什么我不断收到此错误。错误无法将方法组“NextFeature”转换为非委托类型“ESRI.ArcGIS.Carto.IFeatureSelection”。您是否打算调用该方法?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;


namespace ArcMapAddin1
{
    public partial class frmParcelReader : Form
    {
        public frmParcelReader()
        {
            InitializeComponent();
        }


        public void ReadData()
            {

                //IMxDocument pMxDoc =  default(IMxDocument);
                 IMxDocument pMxDoc = ArcMapAddin1.ArcMap.Document;
                //IMap pMap = default(IMap);
                IMap pMap = pMxDoc.FocusMap;
                //IFeatureSelection pFLayer = default(IFeatureSelection);
            IFeatureLayer pLayer = pMap.get_Layer(0) as IFeatureLayer;    

            IFeatureSelection pFLayer = pLayer as IFeatureSelection;

            string stopHere2 = "";

                for (int Count = 0; Count <= pMap.LayerCount - 1; Count++) {

                    //if (pMap.LayerCount == "sde.GIS.parcels_adacounty")
                    if (pLayer.Name == "sde.GIS.parcels_adacounty")
                    {
                        //pFLayer = pMap.get_Layer(0)

                       //string thisString = pFLayer.SelectionSet.IDs.ToString();


                        IFeatureCursor pFCursor = null;

                        //pFLayer.SelectionSet.Search(null, false, pFCursor);


                        //IFeature pFLayer = pLayer(IFeature);

                        pFLayer = pFCursor.NextFeature;

                        if (pFLayer.SelectionSet.Count != 0) {
                            //lblParcel.Text = pF.Value.Fields.FindField("PARCEL");
                            //lblPrimaryOwner.Text =    pF.Value(pF.Fields.FindField("PRIMOWNER"));
                            //lblMailingAddress.Text = pF.Value(pF.Fields.FindField("ADDCONCAT"));
                            //lblPropertyAddress.Text = pF.Value(pF.Fields.FindField("ADDRESS"));
                        } else {
                            //if (sender == "Button")
                               // MessageBox.Show("Please select a Parcel.");
                        }

                        break; // TODO: might not be correct. Was : Exit For
                    }
                }

            }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            ReadData();
        }
    }
}

【问题讨论】:

  • pFCursor.NextFeature 返回什么?如果它是 pfLayer 类型的对象,您可能想要更改 pFLayer = pFCursor.NextFeature;到 pFLayer = pFCursor.NextFeature();

标签: c# vb.net vba esri


【解决方案1】:

NextFeature 是一种在调用时返回IFeature 的方法(参见文档here)。因此,您需要更改:

pFLayer = pFCursor.NextFeature;

到这里:

pFLayer = pFCursor.NextFeature();

这样函数就被实际调用了。原始代码行基本上是获取一个函数指针并尝试将其转换为IFunction,因此出现错误。

【讨论】:

    【解决方案2】:

    我想你只需要将() 添加到NextFeature 的末尾即可。

    像这样:

    pFLayer = pFCursor.NextFeature();
    

    当然,pFCursor需要先初始化为null以外的东西,否则运行代码会崩溃。

    【讨论】:

      【解决方案3】:

      NextFeature 是一个必须用空括号调用它的方法:

      pFLayer = pFCursor.NextFeature();
      

      【讨论】:

        【解决方案4】:

        这部分永远不会起作用:

        IFeatureCursor pFCursor = null;
        pFLayer = pFCursor.NextFeature;   // pFCursor is sure to be null
        

        但这将是一个运行时错误。想必 NextFeature 是一个方法(函数),那么你需要:

        IFeatureCursor pFCursor = ...     // something valid
        pFLayer = pFCursor.NextFeature(); // always use () in a method call
        

        【讨论】:

        • 我试过了,但是我找不到任何东西来替换 null。我不断收到错误。 “无法将类型 'ESRI.ArcGIS.Geodatabase.IFeature' 隐式转换为 'ESRI.ArcGIS.Carto.IFeatureSelection'。存在显式转换(您是否缺少演员表?)”
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-18
        • 2010-09-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-28
        相关资源
        最近更新 更多