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.

Example:
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

Tested with B4A 13.00-jdk-19.0.2-android 34
 

luc-dev

Member
Licensed User
Longtime User
Yes, the csPost_P2 is in app_const Process_Globals

Example:
Sub Process_Globals
    Public Const csPost_P2 = "MyText" As String
...
End Sub
 

Daestrum

Expert
Licensed User
Longtime User
Do you reference app_const before assigning the value to csPost_P1 ?
 

luc-dev

Member
Licensed User
Longtime User
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.
 

luc-dev

Member
Licensed User
Longtime User
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

  • Test_const_ini.zip
    11.4 KB · Views: 26
Top