Upcoming feature for Pro addin developers - New Table Object Model
Here is some info from our help topic on this upcoming feature. It will be available in the 17.0 beta.
.NET AddIn Developers can now take advantage of a new Catalog of open tables that is kept up to date as tables are opened and closed. You can list the tables, open and close tables and get all the properties of a table. Using the Tables collection which is always up to date relieves your addin from having to listen to events to know when tables are added or removed. Additionally each table has all of the need information as properties and methods which are also kept up to date. Having .net object model make creating your own ui dialogs and windows that much easier.
There are three main interfaces Catalog, Tables, and Table.
Catalog Object and Tables Collection
The Catalog is accessed from the main Pro Interface IMapInfoPro. Catalog. It contains an always up to date collection of Tables. Hidden tables are not in the Tables collection but the ICatalog. HiddenTable(String) method can be able to access them if needed. The Catalog also contains methods to Open and Close tables. In addition you can see if there is a selection and get the Table that represents the selection using ICatalog. ConvertSelectionToTable()
You can easily list or enumerate the tables in the collection or access one by its table Alias (called table Name in MapBasic )
The Catalog is an equivalent to using the MapBasic statements and functions "open table", NumTables(), SelectionInfo().
Table Properties and Methods
The ITable interface represents an open table in MapInfo Pro. All of its over 55 Read Only properties are kept up to date. You can get the Columns of the table, its File Path, CoordSys, Data Format and many more. A few properties return a new object each time like BoundsMin and BoundsMax to avoid the performance bottleneck of keeping them up to date as data changes. There are methods to Close the table, Check if it is use by a background process, check if there are pending edits and more. Note: Attempting to access a reference to any table's properties or methods after it is closed will cause an exception.
The Table Interface is an equivalent to using the MapBasic functions TableInfo() and ColumnInfo(). You still need to use MapBasic statments like "set table ..." to change table properties.
Samples and Examples
There are code snippets in the help topics to simply show how to use the new types like this:
public static void MapInfoPro_OpenTableEnumerate(ICatalog catalog)
{
try
{
// Open a Table
catalog.OpenTable(@"c:\work\data\asia.tab");
// List all readonly tables
foreach (var table in catalog.Tables.Where(t => t.IsReadOnly))
{
Console.WriteLine($"Table {table.Alias} is readonly");
}
}
catch (MapBasicException e)
{
Console.WriteLine($"Table not opened: {e.Message}");
throw;
}
}
Refer to the Sample Applications installed with MapBasic. The TableCatalogObjectModel sample includes all the snippets from the help file in Snippets.cs. It also creates a window when run that lets you click on an example in the UI for a property or methods and jump right in to the debugger in the sample code. Check it out.
- SAMPLES\RIBBONINTERFACE\DotNet\TableCatalogObjectModel