C#你打算调用方法吗?

时间:2012-08-08 14:18:56

标签: c# vb.net vba esri

Vba代码我试图转换为C#。我变得非常接近,但我可以弄清楚为什么我一直收到这个错误。错误无法将方法组“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 个答案:

答案 0 :(得分:8)

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

pFLayer = pFCursor.NextFeature;

到此:

pFLayer = pFCursor.NextFeature();

这样实际调用了该函数。原始代码行基本上是一个函数指针,并试图将它转换为IFunction,因此错误。

答案 1 :(得分:5)

我认为您只需要将()添加到NextFeature的末尾。

像这样:

pFLayer = pFCursor.NextFeature();

当然,pFCursor首先需要初始化为null以外的其他内容,否则在运行代码时会崩溃。

答案 2 :(得分:3)

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

pFLayer = pFCursor.NextFeature();

答案 3 :(得分: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