Process Globals (Erel asked for post here)

roarnold

Active Member
Licensed User
Longtime User
Afternoon,

I have an application that has five modules where several of the modules are just code modules.

The issue is I declare a variable in the Process Globals but the variable is not seen by the other modules.

I noticed this when trying to pass information to a code module and the variable was empty.

In using breakpoints in the first Activity Module, the variable get what is should from a DB query. When moving to the second Activity Module it does not see the variable and I receive an error that the variable I am trying to use has not been declared.

I know this is one of those beat to death questions but the books say that a Process Global variable should be seen by all modules.

Thanks,
Ron
 

margret

Well-Known Member
Licensed User
Longtime User
This is true but if you declare the variable in the Main activity like.

Dim ABC as Int

You will need to access it in the code module like:

Main.ABC.

You can see this if your working in the code module and type the name of the activity like:

Main.

Once you type the period, a window will open showing all the Process_Globals you have.
 
Last edited:
Upvote 0

roarnold

Active Member
Licensed User
Longtime User
Hi Margaret,

Interesting, and believe that would be the outcome. This I assume also works if going to another Activity as well and Service modules.

Appreciate the help,

Thanks,
R
 
Upvote 0

roarnold

Active Member
Licensed User
Longtime User
Hi, Thanks for the help.

Question. Then the Process Globals are not really visible across the modules. Does 2.2 B4A help with this or is it going to be this way.

Interesting, when I placed the period it gave me a list but did not have my variable required in it. I placed the Activity name where the was located in front of it anyway and it works so.....

Thanks Again,
R
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
When you want to access a process global variable in any module other than the module where the variable is defined you must put as a prefix the name of the module where the variable is defined. A process global variable must be declared only once in one module. If you declare a process global variable with the same name in two different modules these are considered as two different variables !
Like Main.Var1 and Module.Var1.

Since version 2.2 of Basic4Android it is good practice to use either Public or Private instead of Dim to declare variables in Modules. Variables declared as Private cannot be accessed from outsides the module where they are defined.

Best regards.
 
Upvote 0
Top