How to compile MapBasic from TextPad
Posted: Wed Jul 26, 2006 5:24 pm
I posted this to the MapInfo Mailing List in response to a user's query regarding the use of MapBasic(R) with TextPad.
In 2003, Niels Fahse posted a useful MapBasic syntax definition file to the TextPad website, but there isn't a good description for compiling and linking MapBasic code.
MapBasic is a programming language for controlling the desktop mapping program, MapInfo Professional(R). It compiles source from its own specialized syntax into pseudo-code which MapInfo then executes.
MapBasic comes with a limited development environment and a lot of people turn to alternatives such as TextPad.
MapBasic allows for separate compilation of modules: Source files (with an extension of .mb) are compiled into intermediate object files (with an extension of .mbo). A "project" file (with an extension of .mbp) controls the linker, which produces the final pseudocode executable (with an extension of .mbx).
MapInfo has built a capability for compiling and linking MapBasic code on the command line of the MapBasic executable, so it's possible to create a TextPad tool utilizing this capability.
Although TextPad can capture output from a command-line tool, and parse it to locate where the compiler said the error occurred, MapBasic thwarts this capability, because the compiler always writes compilation errors to a file with an extension of .err, even when MapBasic is run from the command line. If there are no errors, there is no .err file when MapBasic finishes.
If the MapBasic compiler had a way to send errors to standard output instead of the .err file, you could capture the output in TextPad. But it doesn't, and MapInfo is unlikely to add this functionality.
The best you can do is to open the .err file in TextPad after compilation is finished. Unfortunately, there doesn't appear to be a way to make a TextPad "tool" perform two actions. TextPad's macro functionality appears to be limited to editing. So you'll have to make a DOS batch file like the following:
Save this in a file named MBTextPad.bat in the same directory as Mapbasic.exe. Then add a tool to TextPad (Configure->Preferences..., Select "tools" on the right-hand side, then Add->Program...) that runs MBTextPad.bat. The parameters should be
including all of the quotes. Make sure you have allow multiple instances unchecked in Configure->Preferences->General or Textpad will open the .err file in a separate instance. This method will even work for MapBasic source files whose names have spaces in them (TextPad is a little too helpful putting quotes around parameter values with spaces in them). Perhaps someone is willing to write a VBScript to make this a bit less clunky.
Hope this helps
In 2003, Niels Fahse posted a useful MapBasic syntax definition file to the TextPad website, but there isn't a good description for compiling and linking MapBasic code.
MapBasic is a programming language for controlling the desktop mapping program, MapInfo Professional(R). It compiles source from its own specialized syntax into pseudo-code which MapInfo then executes.
MapBasic comes with a limited development environment and a lot of people turn to alternatives such as TextPad.
MapBasic allows for separate compilation of modules: Source files (with an extension of .mb) are compiled into intermediate object files (with an extension of .mbo). A "project" file (with an extension of .mbp) controls the linker, which produces the final pseudocode executable (with an extension of .mbx).
MapInfo has built a capability for compiling and linking MapBasic code on the command line of the MapBasic executable, so it's possible to create a TextPad tool utilizing this capability.
Although TextPad can capture output from a command-line tool, and parse it to locate where the compiler said the error occurred, MapBasic thwarts this capability, because the compiler always writes compilation errors to a file with an extension of .err, even when MapBasic is run from the command line. If there are no errors, there is no .err file when MapBasic finishes.
If the MapBasic compiler had a way to send errors to standard output instead of the .err file, you could capture the output in TextPad. But it doesn't, and MapInfo is unlikely to add this functionality.
The best you can do is to open the .err file in TextPad after compilation is finished. Unfortunately, there doesn't appear to be a way to make a TextPad "tool" perform two actions. TextPad's macro functionality appears to be limited to editing. So you'll have to make a DOS batch file like the following:
Code: Select all
@echo off
if %1 == %2 goto link
mapbasic -Nosplash -D %1
goto ckerr
:link
mapbasic -Nosplash -L %1
:ckerr
if exist %3 "C:\Program Files\TextPad 4\textpad" %3Code: Select all
"$FileName" "$BaseName.mbp" "$BaseName.err"Hope this helps