Android Question Process_Globals

Harris

Expert
Licensed User
Longtime User
Two Activity modules with process_globals of the same name...
Are they actually Activity_Mod_A.act_stat and Activity_Mod_B.act_stat or are they in fact just one instance of a global called act_stat throughout the app?

Just a tad confused...
Thanks


B4X:
Activity_Mod_A

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim logact As String
    Dim act_stat As Int
    Dim InLogAction As Boolean : InLogAction = False
    Dim acttimelog As Timer
    Dim MakeLRec As Boolean
End Sub

Activity_Mod_B

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim logact As String
    Dim act_stat As Int
    Dim InLogAction As Boolean : InLogAction = False
    Dim acttimelog As Timer
    Dim MakeLRec As Boolean
End Sub
 

imbault

Well-Known Member
Licensed User
Longtime User
Just try it by yourself, Activity_Mod_A.act_stat and Activity_Mod_B.act_stat will be hopefully different variables
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
I tried it, it works calling Activity_Mod_B.act_stat, so I guess the answer is:
it IS a distinct proc_global. Thinking about it, we always prefix any global by the module where it was born and resides, unless it is within the same module.

Being a lazy hack, I often create new modules by copying an existing (and proven) module - then modify to suit the new requirement. That goes for layouts as well. Give me a loaded gun and I will shoot myself in the foot until:
A) I empty the cartridge and suffer no harm..
B) The gun jams (something broke) and I must find another solution
C) I blew my foot off and must now seek professional help.

I know, the last three words from option C is your advice to me... HAHA!
 
Upvote 0

imbault

Well-Known Member
Licensed User
Longtime User
Technically , no problem using same variable name on all the activities on Process_Globals, but honestly, it's a total mess for dev

So try to be not so lazy, come one!!!
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Yes, I see from my example above that these proc_globals should be moved to a code module where they are only declared once.
Each Activity form (and a few services) use them but only in the context of the active form.

Thanks for pointing out the errors in my lazy ass ways...

I shall en-devour to persevere... (Chief Dan George / Outlaw Josey Wales...)
 
Upvote 0
Top