The answer is to write some custom dialogs in a separate module that you easily can reuse across your MapBasic applications.
In the MapBasic Common Library that you can find on the Community Download site, you can now find two such custom dialogs: http://communitydownloads.pbinsight.com/code-exchange/download/mapbasic-common-libraries
DLGSelectTable
This module contains a single dialog for selecting a table. The module is defined in this file: Dialogs\DLGSelectTable.mb.
This MapBasic module has only one public function:
Function DLGSelectTable(
ByVal nTypesToUse As Integer '**Integer value determining what table types to show in the list
, ByVal sTitle As String '**Dialog Title
, ByVal sTitleList As String '**Title above the List of Tables
, ByVal sOpenButtonTitle As String '**Title on the Open button
, ByVal bAllowUserToOpen As Logical '**Can the User open additonal tables?
, ByVal sDefaultTableName As String '**Preselected Table if Open
) As String '**Returns the table selected or "" if dialog was cancelled
This function is used to to ask the user to select one of the currently open tables. If you want you can also let the user open additonal tables into MapInfo Pro and select one of these.
Prerequisites
In order to use this function, you need to include the file Dialogs\DLGSelectTable.def in the source file where you use the function.
You also have to include the Compiled MapBasic Object Files, mbo, in your MapBasic Project File. As this module is using a number of other modules, you need to include all these modules in your project file as well:
- ARRAYLib.mbo
- DEBUGLib.mbo
- ERRORLib.mbo
- TABLELib.mbo
- DLGSelectTable.mbo
Using the dialog
The numeric values used to define what table types to use, can be found in the file TABLELib.def:
Define TAB_USE_ONLY_MAPPABLE 1
Define TAB_USE_TEMP 2
Define TAB_USE_BASE 4
Define TAB_USE_LINKED 8
Define TAB_USE_WMS 16
Define TAB_USE_WFS 32
Define TAB_USE_FME 64
Define TAB_USE_RASTER 128
Define TAB_USE_GRID 256
Define TAB_USE_READONLY 512
Define TAB_USE_TILESERVER 1024
You can also find some predefined constants for a set of tables typically used such as TAB_USE_ALL, TAB_USE_ALL_MAPPABLE, TAB_USE_ALL_BUT_IMAGES and TAB_USE_ALL_MAPPABLE_BUT_IMAGES.
So imagine you need to ask the user to pick a mappable table that you can add new records to. That means you basically want all mappable tables that aren't images and aren't read-only. You can specify these using this expression:
TAB_USE_ALL_MAPPABLE_BUT_IMAGES - TAB_USE_READONLY
To use the dialog in your code, you can specify it's use like this:
sTab = DLGSelectTable(TAB_USE_ALL_MAPPABLE_BUT_IMAGES - TAB_USE_READONLY, "Select a table to add records to", "Mappable and Editable Tables", "Open", FALSE, "")
If sTab = "" Then
Note "You didn't select a table!"
Exit Sub
End If
DLGSelectTableAndColumn
There is another custom dialog called DLGSelectTableAndColumn. It allows you to present the user with a dialog where he can select a table as well as a column.
Function DLGSelectTableAndColumn(
ByVal nTableTypesToUse As Integer '**Integer value determining what table types to show in the list
, ByVal sTitle As String '**Dialog Title
, ByVal sTitleTableList As String '**Title above the List of Tables
, ByVal sDefaultTableName As String '**Preselected Table if found in nthe List of Tables
, ByVal nColumnTypesToUse As Integer '**Integer value determining what Column Types to show in the list
, ByVal sTitleColumnList As String '**Title above the List of Columns
, ByVal sDefaultColumnName As String '**Preselected Column if found in nthe List of Columns
, ByVal sOpenButtonTitle As String '**Title on the Open button
, ByVal bAllowUserToOpen As Logical '**Can the User open additonal tables? TRUE, yes he can't
) As Logical '**Returns TRUE if a Table and Column was selected or FALSE if dialog was cancelled
The return value of this function is a Logical. It returns TRUE if the user did select a table and a column. And it returns FALSE if the user cancelled the dialog.
The dialog looks like this:
![DlgSelectTableAndColumn]()
Prerequisites
In order to use this function, you need to include the file Dialogs\DLGSelectTableAndColumn.def in the source file where you use the function.
You also have to include the Compiled MapBasic Object Files, mbo, in your MapBasic Project File. As this module is using a number of other modules, you need to include all these modules in your project file as well:
- ARRAYLib.mbo
- DEBUGLib.mbo
- ERRORLib.mbo
- TABLELib.mbo
- DLGSelectTableAndColumn.mbo
Using the dialog
The numeric values used to define what table types to use, is like to above. Look in TABLELib.def. Similar the file COLUMNLib.def holds a list of column types that can be used.
As this function returns TRUE/FALSE, you will have to use two additional functions to get the name of the table and column selected by the user:
- Function DLGSTCGetTableName() As String
- Function DLGSTCGetColumnName() As String