Parts of the MapInfo MapBasic API are accessed as follows:

  Alter ButtonPad "Main"
        Add ToolButton
            ID 101
            Icon 8
            Calling OnToolClicked
            HelpMsg "Custom Edit Tool.\nCustomTool"

The Alter ButtonPad statement with nested Add and Show commands looks a bit like the builder pattern or a "fluent" interface in object oriented languages. I'm wondering if the Alter ButtonPad statement is defined with a language construct that a developer can take advantage of when building a MapBasic application.

For example I'm developing an application that will dynamically populate a form with drop-down lists. It would be nice if I could build up the constraint lists with something like:

Create ConstraintCollection
    Add Property
        Name "property"
        Add Value "value 1"
        Add Value "value 2"
        Add Value "value 3"

Is defining this Create ConstraintCollection statement something that is possible with MapBasic?

1 Answer 1



I would consider them part of the same statement: Alter ButtonPad.

This statement can be used to modify an existing ButtoPad or toolbar from within a MapBasic application.

You can also create your own menu or buttonpad using these statements:

  • Create Menu
  • Create ButtonPad

All the MapBasic documentation can be found on the Pitney Bowes web site. It's easiest to go thru the mapinfo.com site however:

Here you can find all documentation for our products. Here is a more direct link to the documentation for MapInfo MapBasic: MapInfo MapBasic documentation

If you are new to MapBasic have a look a this article on gis.se: Getting Started with MapBasic

MapBasic is not an object orientated language, so adding your own statements as you suggest above is not doable - at least not the way you suggest it.

What I tend to do to get it closer to object orientated programming, is to create modules for each of my "objects". These modules can then have an Create procedure or function and I can also add my own Add functions to the module. In that way I can encapsulate the logic of the "object" in a module and access this "object" thru the available procedures and functions.

Here's a very basic example of the definition of such an module

    StartPoint  As T_MI_POINT
    EndPoint    As T_MI_POINT
End Type

Declare Sub tmilCopy(     tmilFrom As T_MI_LINE     'Input T_MI_LINE
                        , tmilTo As T_MI_LINE       'Output T_MI_LINE
Declare Sub tmilOffset(   tmil As T_MI_LINE     'T_MI_LINE to offset - this will be changed
                        , ByVal fDistance As Float  'Distance to offset the T_MI_LINE
                        , ByVal fDirection As Float 'Direction to offset the T_MI_LINE

Declare Function tmilAreIdentical(    tmil1 As T_MI_LINE    'first T_MI_LINE to compare
                                    , tmil2 As T_MI_LINE    'second T_MI_LINE to compare
                                    ) As Logical

Declare Function tmilToLine(      tmil As T_MI_LINE 'Creates a line using the coordinates of the T_MI_LINE
                                ) As Object         'Returns a line with the current style
Declare Function tmilToLineWithStyle(     tmil As T_MI_LINE 'Creates a line using the coordinates of the T_MI_LINE
                                        , ByVal penUse As Pen   'Pen to use for the line to create
                                        ) As Object         'Returns a line with the style given

But this is not near the features of a modern object orientated language.

You can of course also choose to develop your application using an OOP and then integrate into MapInfo Professional using the Intergrated Mapping interface, or you could develope somethings in OOP and access these in a assembly from MapBasic.

With the upcoming 64bit version of MapInfo Professional were are extending the .NET API available to developers. This should be released in the October/November time frame of 2014.

  • Thanks Peter. I guess my question should be more like "can I develop modules that define new statements?". I'll update my question to clarify this. Commented Aug 13, 2014 at 14:56
  • PS: based on the documentation I've read I think this is not possible, but just wanted someone with deeper knowledge to confirm. If you can confirm, I will accept your answer. Commented Aug 13, 2014 at 15:20
  • 1
    John, I have extended my answer a bit to try and cover your question a bit better. Let me know if you need more details Commented Aug 14, 2014 at 6:10
  • Fantastic! That's an excellent code sample. Thanks for your help Peter. Commented Aug 14, 2014 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.