corwin42 Expert Licensed User Longtime User Apr 26, 2011 #1 I would love to have a builtin Clone method for structures. This code example explains it all: Code: '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: Code: 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: Code: Database.InsertTableData(sq, "BatteryData", BD.ToArray)
I would love to have a builtin Clone method for structures. This code example explains it all: Code: '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: Code: 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: Code: Database.InsertTableData(sq, "BatteryData", BD.ToArray)
Erel B4X founder Staff member Licensed User Longtime User Apr 26, 2011 #2 You can create a clone method using RandomAccessFile.WriteObject/ReadObject. Write the structure to a bytes array and then read it. It will clone your data.
You can create a clone method using RandomAccessFile.WriteObject/ReadObject. Write the structure to a bytes array and then read it. It will clone your data.
JesseW Active Member Licensed User Longtime User Aug 9, 2011 #3 How about views? RandomAccessFile doesn't include views as supported types. Is there a way to clone a view? My situation is I need 48 labels to display info as a grid. There are six columns. I'd rather not define them all in the designer. But if I could define one, I could load the layout and clone the rest without creating all six columns in code inside a loop. Thanx... Edit: after some more thought, I realized another way I could achieve what I wanted without too much duplicate coding. But it would still be nice to have the ability to clone an object. Thanks Erel for a superb dev environment Last edited: Aug 9, 2011
How about views? RandomAccessFile doesn't include views as supported types. Is there a way to clone a view? My situation is I need 48 labels to display info as a grid. There are six columns. I'd rather not define them all in the designer. But if I could define one, I could load the layout and clone the rest without creating all six columns in code inside a loop. Thanx... Edit: after some more thought, I realized another way I could achieve what I wanted without too much duplicate coding. But it would still be nice to have the ability to clone an object. Thanks Erel for a superb dev environment
Erel B4X founder Staff member Licensed User Longtime User Aug 10, 2011 #4 Cloning objects is much more complicated than it may sound. An object can hold references to many other objects. Do you want to clone them too (deep copy vs. shallow copy)? If you completely clone a view you will end up with two activities. Other solutions are much simpler and manageable: Basic4android Search: arrays of views
Cloning objects is much more complicated than it may sound. An object can hold references to many other objects. Do you want to clone them too (deep copy vs. shallow copy)? If you completely clone a view you will end up with two activities. Other solutions are much simpler and manageable: Basic4android Search: arrays of views