C# 你打算调用这个方法吗
我正在尝试将Vba代码转换为C。我已经非常接近了,但我可以找出为什么我一直出现这个错误。错误:无法将方法组“NextFeature”转换为非委托类型“ESRI.ArcGIS.Carto.IFeatureSelection”。您是否打算调用该方法C# 你打算调用这个方法吗,c#,vb.net,vba,esri,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 Sys
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();
}
}
}
这部分永远不会起作用:
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
这部分永远不会起作用:
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
我想你只需要在下一个功能的末尾添加 像这样:
pFLayer = pFCursor.NextFeature();
当然,pFCursor首先需要初始化为null以外的值,否则在运行代码时它会崩溃。我认为您只需要添加到NextFeature的末尾 像这样:
pFLayer = pFCursor.NextFeature();
当然,pFCursor首先需要初始化为null以外的值,否则在运行代码时会崩溃。NextFeature是一种调用时返回IFeature的方法。请参阅文档。因此,您需要更改以下内容:
pFLayer = pFCursor.NextFeature;
为此:
pFLayer = pFCursor.NextFeature();
这样函数就被实际调用了。原始代码行基本上是获取函数指针并尝试将其强制转换为IFunction,因此出现了错误。NextFeature是一种在调用时返回IFeature的方法。请参阅文档。因此,您需要更改以下内容:
pFLayer = pFCursor.NextFeature;
为此:
pFLayer = pFCursor.NextFeature();
这样函数就被实际调用了。原始代码行基本上是获取函数指针并尝试将其强制转换为IFunction,因此出现错误。NextFeature是一种必须使用空括号调用的方法:
pFLayer = pFCursor.NextFeature();
NextFeature是一个必须使用空括号调用的方法:
pFLayer = pFCursor.NextFeature();
pFCursor.NextFeature返回什么?如果它是pfLayer类型的对象,则可能需要更改pfLayer=pFCursor.NextFeature;到pFLayer=pFCursor.NextFeature;pFCursor.NextFeature返回什么?如果它是pfLayer类型的对象,则可能需要更改pfLayer=pFCursor.NextFeature;到pFLayer=pFCursor.NextFeature;我试过了,但是我找不到任何可以替换null的东西。我一直在犯错误。无法将类型“ESRI.ArcGIS.Geodatabase.IFeature”隐式转换为“ESRI.ArcGIS.Carto.IFeatureSelection”。存在显式转换是否缺少强制转换?我尝试过,但找不到任何可以替换null的内容。我一直在犯错误。无法将类型“ESRI.ArcGIS.Geodatabase.IFeature”隐式转换为“ESRI.ArcGIS.Carto.IFeatureSelection”。存在显式转换。是否缺少强制转换?