B4J Question Is it possible to assign an array to a structure (type)?

Omar Moreno

Member
Licensed User
Is there any way to assign the contents of an array in a single line to a structure type variable?

B4X:
Sub Process_Globals
   Type RowType(data1 As Int, data2 As String, data3 As Objet) '<---data... N
   Public Col As RowType
End Sub

'Then in a Sub ...

Sub PrintPDF
    Col.Initialize
    Col = Array As Objet(1, "dato x", "dato y") '<--- Error
End Sub
 

Daestrum

Well-Known Member
Licensed User
Example
B4X:
Sub Process_Globals
 Private fx As JFX
 Private MainForm As Form
 Type RowType(data1 As Int, data2 As String, data3 As Object) '<---data... N
 Dim Col As RowType
End Sub
Sub AppStart (Form1 As Form, Args() As String)
 MainForm = Form1
 MainForm.Show
 Col.Initialize
 setFields(Col,1,"fred","anObject")
 Log(Col)
 Log(Col.data1)
End Sub
Sub setFields(target As RowType,arg1 As Int,arg2 As String,arg3 As Object)
 target.data1=arg1
 target.data2=arg2
 target.data3=arg3
End Sub
 

MarkusR

Well-Known Member
Licensed User
or instead of a type use a class with set get property or direct via "constructor"
 
Top