@luis
I think what people are failing to understand is that a module has to be treated as a "black box". Perhaps the following diatribe will help them come to grips with modules.
In effect, modules are independent blocks of code that should be looked on as something that can be compiled in its own right, such as a dynamic library (.dll/.so). Everything that a module needs has to be defined/declared within the module. It has no understanding of the outside world. Likewise, mainline code knows nothing about what is inside a module.
For modules to be able to communicate, they need a mechanism for making the contents accessable from the outside world. This is done using the DeclareModule statement. It performs the same function that the Prototype statement performs for dynamic libraries.
Modules are only grouped together in a program for convenience. The mainline code and the modules can all be compiled together as a single unit, rather than as a main executable and separately compiled libraries. As a result, one has to use the same design constraints that one uses for applications that contain dynamic libraries.
If a structure is used in the mainline, it has to be defined in the mainline. And if that structure contains instances of other structures, they also have to be defined, even if the mainline never uses them. This is even true for programs that don't use modules.
Similarly for modules. All constants, macros, and structures need to be defined within the module if they are referenced in any way. So people should try to get their heads around this, and stop coming up with all kinds of crazy ideas for getting around problems that don't actually exist.
Applications usually have constants, macros, and structures that are used throughout the code. Often they are grouped together in "Include" files. So why not just structure the code as follows, with DeclareModule statements wherever needed?
Code: Select all
;
;----------
;
; mainline code
;
XincludeFile "Constants.pbi"
XIncludeFile "Macros.pbi"
XIncludeFile "Structures.pbi"
.
. mainline code
.
End
;
;----------
;
Module M1
XincludeFile "Constants.pbi"
XIncludeFile "Macros.pbi"
XIncludeFile "Structures.pbi"
.
. module 1 code
.
EndModule
;
;----------
;
Module M2
XincludeFile "Constants.pbi"
XIncludeFile "Macros.pbi"
XIncludeFile "Structures.pbi"
.
. module 2 code
.
EndModule
;
;----------
;
Module M3
XincludeFile "Constants.pbi"
XIncludeFile "Macros.pbi"
XIncludeFile "Structures.pbi"
.
. module 3 code
.
EndModule
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan