TWIAV - Tips & tricks

TWIAV - Tips & tricks

MapBasic Code Samples

On this page you will find some MapBasic code samples, both the program source and the compiled application. Everything on this page is offered "as is" without warranty of any kind, either expressed or implied, including limitation warranties of merchantability, fitness for a particular purpose, and noninfringement.

Unless otherwise stated MapBasic 9.0 has been used to compile the files - this means that the MBXs offered here will only run with MapInfo Professional 9.0 or higher. If you want to use the tools with another (an older) version of MapInfo Professional, you will have to compile the tool using the relevant version of the Mapbasic compiler.

The MapBasic Code Samples Project

The goal of this project is to provide some examples of how to use certain MapBasic functionality - not to offer full-blown applications. The applications below each focus on one 'trick'. You can study the source, modify it to suit your needs and implement it in your own apps.

The following code samples are available here:

DrawMode DM_CUSTOM_POLYGON Sample Code

This application demonstrates how to use a ToolButton with a custom DrawMode in your MapBasic application:

  • The ToolButton has the DrawMode DM_CUSTOM_POLYGON (35) assigned to it;

  • The Polygon drawn by the user is stored in an Object variable using the CommandInfo() function: oPolygon = CommandInfo(CMD_INFO_CUSTOM_OBJ);

  • The Object oPolygon - together with some attribute data - is stored in a predefined table using the Insert Statement.

Please see the file below for CustomPolygon.MB and CustomPolygon.MBX.

The table used in the example - Polygons.TAB - is also included in the zip file:
Custom Polygon Creation

Projection taken from table

As you will see: the projection used in this code sample is French Lambert-93. This projection is actually taken from the sample file used here.

If you want to use another projection you just have to change the projection of the polygon table...

More code samples will follow...;-)

What do you think of these code samples? If you have any , please let me know.