Bug? Const not always initialized at debug time

luc-dev

Member
Licensed User
Longtime User
At DebugTime, B4A Const declared in Sub Class_Globals are not initialized when the value is assigned from another module. Everything works as expected at runtime. B4i 8.51 doesn't have this issue.

[CODE lang="b4x" title="Example" highlight="5,6"]Sub Class_Globals
' OK
Public Const State_unknown = -1 As Int

' Not initialized at debugtime
Public Const csPost_P1 = app_const.csPost_P2 As String
End sub[/CODE]

Tested with B4A 13.00-jdk-19.0.2-android 34
 
Yes, the csPost_P2 is in app_const Process_Globals

[CODE lang="b4x" title="Example"]Sub Process_Globals
Public Const csPost_P2 = "MyText" As String
...
End Sub[/CODE]
 
Do you reference app_const before assigning the value to csPost_P1 ?
 
app_const is a code module, not a class module and I think in B4X the compiler takes care of the dependencies and modules const initialization.
app_const has only one Sub which is Process_Globals.
As said in post #1, everything is ok at runtime with b4A and in debug mode and runtime with b4i. Only the b4a debug mode seems problematic.
 
I tried to reproduce the problem in a small project but I was unable to as it works as expected. The global flow of the B4XPages app is :
Starter service -> Call app_dm.InitApplication -> MyClass.Initialize which init other child classes that are using app_const in their initialization section.
Here is a small project, but no issue.

The real app(s) still have the problem.
I can use workarounds like changing the data module to a singleton class and call initialize or get ride of the const and use var instead, but I wish I had been able to find the source of this problem...

Here is the small project, just showing the global flow fo calls :)
 

Attachments

Back
Top