MapBasic is the application development environment for MapInfo Professional. You can download MapBasic for free. Documentation about MapBasic (User Guide and Reference Guide) is also available.
On these pages you will find tips & tricks regarding the development of your own MapBasic applications.
Information is given about additional tools you can use during the development process:
MapBasic IDE: a new MapBasic editor
Notepad++: to write MapBasic programs
Pelles C: to create a DLL with custom toolbar buttons
MapBasic IDE is a new editor, or should we say: an Integrated Development Environment (IDE), to write, compile and run your MapBasic applications. MapBasic IDE is developed by Mustafa ÖZÇETiN, and can be downloaded from here. |
The first release of the English version of this editor was announced on the MapInfo-L on 22 February 2012 and immediately attracted the attention of the community. And on 24 September 2012 MapBasic IDE 1.4 Beta1 has been released. The main new feature in this release is the Dialog Designer. |
The MapBasic Development Environment contains a built-in text editor that you can use to create and edit MapBasic programs. But if you already have a favorite text editor, you can use that editor for editing your MapBasic program.
Let's suppose that Notepad++ is your editor of choice. Haven't heard of Notepad++ yet? Notepad++ is a very powerful text editor, it's free and it's source is published under the GPL (GNU General Public License).
Here you will find some information on how to configure Notepad++ so that you can use it to develop your own MapBasic applications quickly, easily and effectively. Topics covered here include:
Syntax Highlighting and Auto Completion
- Updated to MapBasic 10.5;Compiling MapBasic Program Source without leaving Notepad++
;Start a MapBasic Application from within Notepad++
;Search MapBasic Help with keywords from within Notepad++
;Modular Programming: Linking a MapBasic Project File from within Notepad++
;Compiling Object Files, Linking Project File and Running Application, all with one Mouse click or Keystroke
.When you start to develop larger, more complex MapBasic applications, it is worth your while to take advantage of MapBasic’s project-file capabilities. Instead of typing the entire program into a single source file, you might store the source code into two or more smaller source files. Next you will need to create a project file listing all the modules in the project.
When compiling a modular source file (*.mb) an object file (*.mbo) will be created. After you have compiled all the modules in the project, you are ready to create your application file (*.mbx). To do so you will have to link the project file (*.mbp). This project file tells the MapBasic linker how to combine separate modules into a single, executable application.
If you want to know more about modular programming with MapBasic, please refer to the MapBasic User Guide. You can also have a look at the Samples which come with MapBasic, as most of them have a modular structure.
Now that you are using Notepad++ to manage the modules in your MapBasic project (using the Multi-Document capabilities of Notepad++), you may not want to switch back to MapBasic whenever you need to compile a module and/or want to link the project. Fortunately you can configure Notepad++ to create and run the application without leaving your favorite editor ;-) One way to do so would be to call a batch file to start MapBasic in the background.
Please see the batch code below. This will first check that your file is an MBP file; if so, it will call MapBasic to compile or recompile each and every module/object file in the project. (If the source code is not available, the previously compiled object file will be used instead.) After compiling all the modules the project will be linked. When the executable is ready, the script will offer you to run the application immediately. In short, this script assists you in recreating the whole application with a single mouse click or keystroke. If any compiler or linker errors do occur, you will be prompted to press any key and the error file will be opened for you.
Please note: new batch code (published 6 July 2010) - the previously published code appeared not to work; sorry for that ;-)
For this batch script to work, all the modules/object files within the project must be available in the same directory/folder. If someone knows how to improve the script to cater for modules in different folders: please let me know...
@echo off
setlocal enabledelayedexpansion enableextensions
rem Link_MBP.bat
rem This file is used to link a MapBasic Project File from within Notepad++
rem Before linking the project all the source files which are part of the project will be compiled
rem After linking the resulting application will be run
set MBExecPath="C:\Program Files\MapInfo\MapBasic\MAPBASIC.EXE"
set NPPExecPath="C:\Program Files\Notepad++\notepad++.exe"
echo.
echo MapBasic Project File ^(^*.mbp^) Linker
echo.
if not exist !MBExecPath! (
echo Cannot find MapBasic, expecting it to be here:
echo !MBExecPath!
pause
goto :EOF
)
if not exist !NPPExecPath! (
echo Cannot find Notepad++, expecting it to be here:
echo !NPPExecPath!
pause
goto :EOF
)
rem Check that the file is a MapBasic Project File
if /i "%~x1" NEQ ".mbp" (
echo Error: file %~dpnx1 is not a MapBasic Project File ^(^*.mbp^)
echo.
pause
goto :EOF
)
echo First, all the source files will be compiled:
echo.
for /f "usebackq skip=1 delims== tokens=2" %%j in (%1) do (
if /i %%~xj EQU .mbo (
rem Check that source code exists
if exist "%~dp1%%~nj.mb" (
echo Compiling %%~nj.mb
!MBExecPath! -server -D "%~dp1%%~nj.mb"
if exist "%~dp1%%~nj.err" (
echo Errors in compilation
echo Press a key to open error log: %~dp1%%~nj.err.
pause
!NPPExecPath! "%~dp1%%~nj.err"
goto :EOF
)
) else (
echo.
echo Source file not present:
echo %%~nj.mb
echo.
echo Using previously compiled object file instead:
echo %~dp1%%j
if not exist "%~dp1%%j" (
echo.
echo Error: cannot find source code ^(^*.mb^)
echo or object file ^(^*.mbo^) for %%~nj
echo.
pause
goto :EOF
)
echo.
)
)
)
echo.
echo Ready to link the MapBasic Project File:
echo.
echo Linking %~1
!MBExecPath! -server -L "%~dpnx1"
if exist "%~dpn1.err" (
echo Errors in linking
echo Press a key to open error log: %~dpn1.err.
pause
!NPPExecPath! "%~dpn1.err"
goto :EOF
)
echo.
echo Completed
echo.
echo Ready to run %~n1.mbx
echo.
echo Press Ctrl-C if you do not want to run the application
echo.
pause
"%~dpn1.mbx"
Steps to follow:
Copy the batch code above and save it to a file Link_MBP.bat. Copy this batch file to the Notepad++ installation folder. (i.e. C:\Program Files\Notepad++\Link_MBP.bat).
Configure Notepad++ to call this batch file by modifying the file shortcuts.xml. You will find this file in the folder %USERPROFILE%\Application Data\Notepad++ (i.e. C:\Documents and Settings\my_user_name\Application Data\Notepad++\shortcuts.xml). Add the following line within the <UserDefinedCommands> tag:
<Command name="Link MapBasic Project" Ctrl="yes" Alt="no" Shift="yes" Key="49">$(NPP_DIRECTORY)\Link_MBP.bat "$(FULL_CURRENT_PATH)"</Command>
This will add an entry to the Run menu: Run > Link MapBasic Project (with the shortcut key Ctrl+Shift+1).
Please note: it is not possible to modify the shortcuts.xml file while Notepad++ is running (because it is locked by the program). So you have to use another text editor to do this (or you can copy the file to another location; modify it ; close Notepad++; copy the file back and restart Notepad++).
Conflicting shortcut keys / Notepad++ Shortcut Mapper
Please note: the shortcut key we use here - Ctrl+Shift+1 - was still available way back in 2008. Nowadays - from Notepad++ 5.x onwards - this key is assigned to default Notepad++ functionality (Search > Jump up > 1st Style). To resolve this conflict, you can use the Shortcut Mapper in Notepad++ (Settings > Shortcut Mapper...) to modify or disable either one of the shortcut keys.
What do you think of these tips about MapBasic? If you have any , please let me know.