1

我正在尝试转换为 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();
        }
    }
}
4

4 回答 4

8

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

pFLayer = pFCursor.NextFeature;

对此:

pFLayer = pFCursor.NextFeature();

以便实际调用该函数。原始代码行基本上是采用函数指针并尝试将其强制转换为IFunction,因此出现错误。

于 2012-08-08T14:22:49.683 回答
5

我认为您只需要添加()NextFeature.

像这样:

pFLayer = pFCursor.NextFeature();

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

于 2012-08-08T14:22:13.870 回答
3

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

pFLayer = pFCursor.NextFeature();
于 2012-08-08T14:23:46.883 回答
2

这部分永远不会起作用:

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
于 2012-08-08T14:21:54.683 回答