Dim QtdTpItens As Int = 50
Type TpItem(taborig As String, id As Int, Qtd As Double)
Public TpItem(QtdTpItens) As TpItem
Dim QtdTpPedItens As Int = 50
Type TpPed(id As Int, fpgto As Int, fentr As Int, TpItem As TpItem)
Public TpPed(QtdTpPedItens) As TpPed
My problem is that I dont know how to insert a Type within another Type...... and then read it again..
When I try :
B4X:
Log("**************** TpPed(0).TpItem " & TpPed(0).TpItem)
Dim TpItemObj() As Object = TpPed(0).TpItem 'the array type must be object or bytes
Dim ct1 = TpItemObj(0) As TpItem
Log("******************* ct1.id " & ct1.id)
I get the error message :
B4A version: 6.50
Parsing code. (0.81s)
Compiling code. (0.81s)
Compiling layouts code. (0.03s)
Organizing libraries. (0.00s)
Generating R file. (0.72s)
Compiling generated Java code. Error
B4A line: 585
Dim TpItemObj() As Object = TpPed(0).TpItem 'the
javac 1.8.0_77
src\b4a\example\main.java:1042: error: incompatible types: _tpitem cannot be converted to Object[]
_tpitemobj = (Object[])(_tpped[(int) (0)].TpItem);Debug.locals.put("TpItemObj", _tpitemobj);Debug.locals.put("TpItemObj", _tpitemobj);
^
Mr. Erel, thanks for infos, but I changed names of Type TpItem > TpItemT and Type TpPed > TpPedT.
And still getting error message see image. Im trying to copy the Type TpItemT(item of the purchase order) into the Type TpPedT (the purchase order).
And then
You have this code in the Starter Service: Main.TpPed(0).TpItem=ct
But in Main you declare: Public TpPed As TpPedT
Which is not an array!
Then you have: Public TpItem(50) As TpItemT
Type TpPedT(id As Int, idnuvem As Int, fpgto As Int, fentr As Int, TpItem As TpItemT)
You use the same name, I wouldn't do it.
Thats wright, it is a Type.
My questions are:
1) Is it possible to have a Type within another Type ?
2) If yes, how do I operate it (writing and reading the enclosed Type.)?
Thanks a lot for your help!
1) Sure, that's what you did: Type TpPedT(id As Int, idnuvem As Int, fpgto As Int, fentr As Int, TpItem As TpItemT)
2) Yes, that's what you did: Log("Main.TpPed.id = " & Main.TpPed.id)
So, what exactly do you want to do?
Do want an array of TpItemT in the TpPedT type ?
Then you should use: Type TpPedT(id As Int, idnuvem As Int, fpgto As Int, fentr As Int, TpItem(50) As TpItemT)
and call it: Log("Main.TpPed.TpItem(2).id = " & Main.TpPed.TpItem(2).id)
Tip: Lists are more powerful than arrays. It is true that you need to first get the item from the list and only then call the object methods, but still I think that it is worth switching to Lists.
Tip: Lists are more powerful than arrays. It is true that you need to first get the item from the list and only then call the object methods, but still I think that it is worth switching to Lists.
Thanks a lot for your orientation. As Im not so expert I have to take a look in my project to undertand how to switch, but I count on your help to clarify questions that may raise. Thanks a lot.