Modules

In mikroBasic PRO for ARM, each project consists of a single project file and one or more module files. The project file, with extension .mbarm contains information on the project, while modules, with extension .mbas, contain the actual source code. See Program Organization for a detailed look at module arrangement.

Modules allow you to:

Each module is stored in its own file and compiled separately; compiled modules are linked to create an application. To build a project, the compiler needs either a source file or a compiled module file for each module.

Include Clause

mikroBasic PRO for ARM includes modules by means of the include clause. It consists of the reserved word include, followed by a quoted module name. Extension of the file should not be included.

You can include one file per include clause. There can be any number of the include clauses in each source file, but they all must be stated immediately after the program (or module) name.

Here’s an example:

program MyProgram

include "utils"
include "strings"
include "MyUnit"

...

For the given module name, the compiler will check for the presence of .emcl and .mbas files, in order specified by search paths.

Main Module

Every project in mikroBasic PRO for ARM requires a single main module file. The main module is identified by the keyword program at the beginning. It instructs the compiler where to “start”.

After you have successfully created an empty project with Project Wizard, Code Editor will display a new main module. It contains the bare-bones of the program:

program MyProject

' main procedure
main:
  ' Place program code here
end.

Other than comments, nothing should precede the keyword program. After the program name, you can optionally place the include clauses.

Place all global declarations (constants, variables, labels, routines, structures) before the label main.

Other Modules

Modules other than main start with the keyword module. Newly created blank module contains the bare-bones:

module MyModule

implements

end.

Other than comments, nothing should precede the keyword module. After the module name, you can optionally place the include clauses.

Interface Section

Part of the module above the keyword implements is referred to as interface section. Here, you can place global declarations (constants, variables, labels, routines, structures) for the project.

Do not define routines in the interface section. Instead, state the prototypes of routines (from implementation section) that you want to be visible outside the module. Prototypes must exactly match the declarations.

Implementation Section

Implementation section hides all the irrelevant innards from other modules, allowing encapsulation of code.

Everything declared below the keyword implements is private, i.e. has its scope limited to the file. When you declare an identifier in the implementation section of a module, you cannot use it outside the module, but you can use it in any block or routine defined within the module.

By placing the prototype in the interface section of the module (above the implements) you can make the routine public, i.e. visible outside of module. Prototypes must exactly match the declarations.

Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code