Hi
I am declaring a couple of custom Type objects to clean up my code, but have hit an issue with attempting to Initialize them directly. Here is some example code showing the issue I am encountering in my app....
.... autocomplete shows Initialize as an option for b.bt or middleMan in that code, but the app hangs due to a nullPointerException.
I know a few 'Init' Subs in a Code Module can solve this, but it smells like we should be able to do it directly.
I am declaring a couple of custom Type objects to clean up my code, but have hit an issue with attempting to Initialize them directly. Here is some example code showing the issue I am encountering in my app....
B4X:
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Type Ob(bt As Button)
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim b As Ob
Dim butt As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
' b.bt.Initialize("") 'fails here
' Activity.AddView(b.bt, 0, 0, 200, 100)
' Dim middleMan As Button
' middleMan = b.bt 'fails here
' middleMan.Initialize("")
' Activity.AddView(middleMan, 0, 0, 200, 100)
' butt.Initialize("") 'normal way works
' Activity.AddView(butt, 0, 0, 200, 100)
b.bt = InitButton 'works
Activity.AddView(b.bt, 0, 0, 200, 100)
End Sub
Sub InitButton() As Button
Dim bbb As Button
bbb.Initialize("")
Return bbb
End Sub
I know a few 'Init' Subs in a Code Module can solve this, but it smells like we should be able to do it directly.