Forum Discussion
HKosova
Alumni
14 years agoI'm afraid, the ItcTableVariable interface is currently COM-incompatible, so you can't cast to it. You'll need to use a generic object-type variable for a table variable and access its properties and methods using reflection. Casting the Iterator property value to ItcTableVariableIterator should work fine though. Here's an example:
Or, if you use C# 4, you can use dynamic late binding. Something along the lines of:
using System.Reflection;
...
object Table1 = tableVars["TheTableVariable"];
// Get the row and column count
int rowCount = (int) Table1.GetType().InvokeMember("RowCount", BindingFlags.GetProperty, null, Table1, null);
int colCount = (int) Table1.GetType().InvokeMember("ColumnCount", BindingFlags.GetProperty, null, Table1, null);
Console.WriteLine("Rows: {0}; columns: {1}", rowCount, colCount);
// Get the table iterator
ItcTableVariableIterator iterator = (ItcTableVariableIterator) Table1.GetType().InvokeMember("Iterator", BindingFlags.GetProperty, null, Table1, null);
while (!iterator.IsEOF())
{
// Do something
iterator.Next();
}
Or, if you use C# 4, you can use dynamic late binding. Something along the lines of:
dynamic Table1 = tableVars["TheTableVariable"];
var iterator = Table1.Iterator;
// -- or --
// ItcTableVariableIterator iterator = (ItcTableVariableIterator) Table1.Iterator;