C#你打算调用方法吗?

use*_*981 1 c# vb.net vba esri

我试图转换为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();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

dso*_*ano 8

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

pFLayer = pFCursor.NextFeature;
Run Code Online (Sandbox Code Playgroud)

对此:

pFLayer = pFCursor.NextFeature();
Run Code Online (Sandbox Code Playgroud)

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


dav*_*soa 5

我想你只需要添加()到最后NextFeature.

像这样:

pFLayer = pFCursor.NextFeature();
Run Code Online (Sandbox Code Playgroud)

当然,pFCursor需要初始化为第一个以外的东西null,否则在运行代码时会崩溃.