Android Question What is the correct way to use the code module?

SMOOTSARA

Active Member
Licensed User
Longtime User
I have created a code module in the program

I have defined the string variables, program fonts, colors of the program and program constants in "Process_Globals"
Finally, a few simple methods that can be used anywhere
For example, click on menu components or change the size of the text to large and small and ...

Is the code module used for this purpose?
 

DonManfred

Expert
Licensed User
Longtime User
Code modules can not use sleep and wait for as events are not supported in code modules.
Switch to b4xpages and forget about such modules
 
Upvote 0

SMOOTSARA

Active Member
Licensed User
Longtime User
Code modules can not use sleep and wait for as events are not supported in code modules.
Switch to b4xpages and forget about such modules

I use b4xpages.
but for example if a method is used everywhere in the program where should it be defined?


B4X:
Sub set_text_size ( num As Int) As Int
    Return GetDeviceLayoutValues.approximatescreensize*num
End Sub


A method similar to this example
Where to define in b4X to be accessible from all sections.
Main or B4xMainPage or Starter service
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Switch to b4xpages and forget about such modules
In B4XMainPage, cross-platform!
No, code modules too are cross-platform and can be used in B4XPages projects. Of course, the code inside them must be "b4x", it must possibly be conditioned by #IF B4A (or B4i or B4J).

Just share them in the same way you share the B4XPages, that is to put them in the "root folder" (if needed, since you can also have code modules that you only use in one of the 3 platforms; in this case, obviously, it is not necessary to share them, just put them in the folder of the specific platform / language).
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
My answer was for this question in post #3.


You could also use a Class module.
Yes but then you have to instantiate it somewhere and it would not be available immediately for every platform.

A code module is as if it were a single instance of a class always accessible and from everywhere, with the exception of the impossibility of handling events.

Code modules are very useful and are exactly the place to write utility routines that can be used by any other part of your projects.
 
Upvote 0
Top