I would love to have a builtin Clone method for structures.
This code example explains it all:
Also a ToArray method would be nice. I use a general Sub for inserting structure data into a database. Currently I have to Write the following to insert a row:
With a ToArray method this will shorten my code to the following line:
This code example explains it all:
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 struc (a As String, b As String)
Dim s1, s2 As struc
End Sub
Sub Activity_Create(FirstTime As Boolean)
s1.Initialize
s1.a = "One"
s1.b = "Two"
' clone s1 object
s2 = s1.Clone
' Result: One Two
Msgbox(s2.a & " " & s2.b, "Output")
' copy reference to object (this works now)
s2 = s1
s2.a = "Three"
'Result: Three Two
Msgbox(s1.a & " " & s1.b, "Output")
End Sub
Also a ToArray method would be nice. I use a general Sub for inserting structure data into a database. Currently I have to Write the following to insert a row:
B4X:
Database.InsertTableData(sq, "BatteryData", Array As Object(BD.Ticks, BD.Duration, BD.Level, BD.Status, BD.Plugged, BD.ScreenOn))
With a ToArray method this will shorten my code to the following line:
B4X:
Database.InsertTableData(sq, "BatteryData", BD.ToArray)