Select to view content in your preferred language

CreateIndex

488
0
06-12-2013 07:45 AM
Labels (1)
DanieliCywyak
New Contributor
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
when trying to add an index to a feature class

the error happens at the last line befor the return statment. please help

protected bool CreateIndex( IFeatureClass featClass, params object[] fieldsNames)
{

IFields pFields = new Fields();
IField pField;
IFieldsEdit pFieldsEdit;
pFieldsEdit = (IFieldsEdit)pFields;
pFieldsEdit.FieldCount_2 = fieldsNames.Length + 1;

int h;
string indexName="";

for (int i = 0; i < fieldsNames.Length; i++)
{
h = featClass.FindField(fieldsNames.ToString());
// pField = featClass.Fields.get_Field(h);
pFieldsEdit.set_Field(i, featClass.Fields.get_Field(h));
pField = null;
indexName = indexName + ((i == 0) ? fieldsNames.ToString() : "," + fieldsNames.ToString());
}

IIndex pIndex= new Index();
IIndexEdit pIndexEdit =(IIndexEdit) pIndex;

pIndexEdit.Fields_2 = pFields;
pIndexEdit.Name_2 = indexName;


  featClass.AddIndex(pIndex); //this the line where the error takes place
return true;
}
0 Kudos
0 Replies