Hi Chuck,
You can call methods in other
submodules just fine. But if you want to call a method of a module that your module is a submodule of then you have a challenge.
How is this?
The scope of modules are downwards. In other words a module can only see it's objects and from it's submodules. Not from the modules that itself might be part of (upward scope).
In the following diagram module2 has no knowledge of objects in module1 and the main solution. And module1 doesn't know of the objects in the main solution. They can only 'look' downwards. The main solution does see all objects of both modules.
- submodules1.png (6.73 KiB) Viewed 10675 times
Now in the next diagram modules 1 and 2 are submodules of the main solution. So both the modules see ONLY their own objects. The main solution however does see all objects of both modules.
- submodules2.png (5.85 KiB) Viewed 10673 times
Oddly enough this is only a restriction when you are developing because when Servoy loads your solution with all it's submodules then it considers all the loaded objects as one solution (in memory).
This is also the reason that you could use an eval() to trigger a method in a module higher up to (module) tree.
So how to work around this?
Well you can go the eval() route and call methods using eval("forms.formName.methodName()").
But that is pretty cumbersome.
Another way would be to use a link module that links all modules.
How does this work ?
You create another module in your workspace that has nothing else than modules referenced.
So in this case the linkmodule has solution, module1 and module2 as it's submodule.
- linkmodule.png (7.78 KiB) Viewed 10674 times
So that's it ?
No, now you reference the linkmodule in all modules (and solution).
So the linkmodule will be the (only) submodule referenced by all other modules.
Now you have a situation where every module is referenced (by way of the linkmodule) to each other.
This way you 'flatten' the scope of the modules and everybody sees everybody.
Next time you add a new module to your solution you only have to reference it in the linkmodule and *BOOM* all other modules see it.
Hope this helps.
P.s. the credit for this little trick goes to the STB people.