Hello again.
Classes are pretty good, it's just time that I need to start using them properly.
A past habit of mine(from VB.NET) is to name Public Properties with the same variables as input parameters. This is exactly what I did here and it did the second trick for this evening to me. Here is the demonstration:
This should work pretty good in VB.NET as Param1, Param2 are used as parameters in Initialize. However, it seems this is an issue in B4A which took me another 1,5 hours to investigate. The exact problem is that whatever you try, all parameters are Null even if you Log them immediately after calling Initialize.
My question is - is this on purpose or it is a bug? If it is the first, Erel, you may be willing to add it as a compile problem because it's not visible at the very first glance.
Classes are pretty good, it's just time that I need to start using them properly.
A past habit of mine(from VB.NET) is to name Public Properties with the same variables as input parameters. This is exactly what I did here and it did the second trick for this evening to me. Here is the demonstration:
B4X:
Sub Button3_Click
Dim test As TestClass
test.Initialize(0, "test")
Msgbox(test.Param2, "msg")
End Sub
B4X:
'Class module
Sub Class_Globals
Private P_param1 As Int
Private P_param2 As String
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize (Param1 As Int, Param2 As String)
P_param1 = Param1
P_param2 = Param2
End Sub
Public Sub Param1 ' rename to PropertyParam1 to get it working
Return P_param1
End Sub
Public Sub Param2
Return P_param2
End Sub
This should work pretty good in VB.NET as Param1, Param2 are used as parameters in Initialize. However, it seems this is an issue in B4A which took me another 1,5 hours to investigate. The exact problem is that whatever you try, all parameters are Null even if you Log them immediately after calling Initialize.
My question is - is this on purpose or it is a bug? If it is the first, Erel, you may be willing to add it as a compile problem because it's not visible at the very first glance.
Last edited: