MapInfo Pro Developers User Group

Welcome to the MapInfo Pro Developers community!  We are a group dedicated to the discussion and understanding of MapBasic and .Net MapInfoPro AddIn development. Bring your questions and ideas here. This group includes several members of the Pro development team from around the world.

Please feel free to start a discussion in the discussion tab or join in a conversation.

Product Information  Ideas Portal  MapInfo Community Downloads

Discussions

Members

Resources

Events

 View Only
  • 1.  Does MapBasic accept an Include statement with "relative folders"

    Posted 07-14-2017 22:03

    I have a set of folders such as the following (the

    topmost of these is a "first level" folder):

     

             ------------

             | MBPgms |

             ------------

                |

         --------------------------            

         |            |

      -------------     --------------

      | Source |     | Include |

      -------------     --------------

       

    "Source" contains my .mb source programs. "Include"

    contains some .def files that I will want to Include 

    in my source program compilation (such as "ListFns.def"

    that I will reference below).

     

    Within my source program "c:\MBPgms\Source\SampPgm.mb",

    in order to Include "ListFns.def" I expect to be able 

    to use the following statement:

     

      Include "..\Include\ListFns.def"

      

    But the MapBasic compiler never finds ListFns.def, and

    the compile finishes with error messages. I assume that

    the folder containing the source program becomes the "base 

    folder" during the compile, so it seems to me that this 

    Include statement should work. (If the Include folder was

    SUBORDINATE to the Source folder, the following DOES work:

     

      Include "Include\ListFns.def"

      

    which tells me that the compiler DOES consider the folder

    of the source code to be the "base folder" during compile.)

     

    Does MapBasic NOT honor "relative folder" specifications?

     

    Thanks,

    Phil Bolian



  • 2.  RE: Does MapBasic accept an Include statement with "relative folders"

    Employee
    Posted 07-15-2017 02:28

    MapBasic does honor the relative paths and can also go levels up the way you have described here. That is exactly the way the Samples that come with MapBasic have been structured.

    Here's an example of the CoordinateExtractor tool where you can see the include statements:

    Include Examples

    And yes, the compiler is using the position of the current file, or the file being compiled, as the starting point. I assume that the Include folder is at the same level as the Source folder, right? If yes, then your relative reference should work. The double points (..) tells the compiler to one level up from the current file position and then back down into the Include folder.

    Here you can see the file structure where the Inc folder is at the same level as the DistanceCalc folder which holds the sourcecode for the tool.

    CoordExtractor File Structure

    And on a side note, you can of course use the same type of relative file reference in the MapBasic project file as well.

    Project File Examples

     



  • 3.  RE: Does MapBasic accept an Include statement with "relative folders"

    Posted 07-15-2017 11:44
    Peter, First, thanks for your quick response. But second, my apologies for a wrong error report on a case that was caused by my own error as an operator. MapBasic DOES work exactly as you have described, which is how I THOUGHT it did – and I no longer experience the error I reported. The errors I encountered must have been due to my unknowingly using the previous version of my program library, which had a slightly different directory structure than the one I described. (And I did try the compiles on multiple programs in that library, never realizing that I was working with a previous vintage library.) Once again, my thanks for your help. Phil Bolian


  • 4.  RE: Does MapBasic accept an Include statement with "relative folders"

    Employee
    Posted 09-27-2017 15:54

    An easier way for users of MapBasic 12.x ( I think it was at least 12) and later is to use a System User Environment variable instead of having to figure out relative folder paths.

    See the MapBasic Help topic title (has some pics):

    Setting Search Paths for MapBasic Include and Module Files

    To make it easier to develop MapBasic libraries of definitions and modules, you can set environment variables for search paths for Include (.def) files when compiling and Module (.mbo) files when linking. By default, MapBasic will search for these files first in the path specified in your MapBasic code and then under the folder where MapBasic is installed. By setting these environment variables you can specify additional folders to search after the path specified in your code but before the MapBasic folder. The environment variables are called MBINCLUDE and MBMODULE for Include and Module files, respectively, and their values should be set to a semi-colon delimited list of folders to search. MapBasic will search the folders specified and all sub-folders beneath them.

     

    You can set environment variables via Control Panel>System>Advanced System Settings>Environment Variables. The variables must be set before you run MapBasic for them to take effect.

     

    To set additional search folders for Include files, set the environment variable MBINCLUDE. For example, if you have libraries of .def files in or beneath the folders C:\My MapBasic Library and C:\Work, set the MBINCLUDE environment variable as follows:

    C:\My MapBasic Library;C:\Work

    **Do not use quotes around the folder names even if the path contains spaces.

     

    To set additional search folders for Module files, similarly set the environment variable MBMODULE. For example, if you have libraries of .mbo files in or beneath the folder C:\My MapBasic Library, set the MBMODULE environment variable as follows:

    C:\My MapBasic Library

     

    Assuming you set your environment variables as above, when compiling MapBasic will search for these .def files first in the folder where the file your are compiling is located, then under C:\My MapBasic Library and its subfolders, next under C:\Work and its subfolders, and last under the folder where MapBasic was installed. If the file utilities.def, for example, is used by multiple applications you’ve written you can put it somewhere under C:\My MapBasic Library or C:\Work and MapBasic can find it without you having to specify the path in the code.

     

    If the file library.mbo, for example, is used by multiple applications you’ve written you can put it somewhere under C:\My MapBasic Library and MapBasic can find it without you having to specify the path in the project file.