Android Question Array question

Bob Spielen

Active Member
Licensed User
Please asking for help,

I have 2 Types

B4X:
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

Im trying to copy arrays......

B4X:
Main.TpPed(0).TpItem=Array(Main.TpItem)
Starter.kvs.Put("tpped", Main.TpPed)

and getting error message:

B4A line: 53
Main.TpPed(0).TpItem=Array(Main.TpItem)
avac 1.8.0_77
src\b4a\example\db.java:90: error: incompatible types: Object[] cannot be converted To _tpitem
mostCurrent._main._tpped[(int) (0)].TpItem = (b4a.example.main._tpitem)(new Object[]{(Object)(mostCurrent._main._tpitem)});
^

What am I doing wrong?
Thanks for help
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Bob Spielen

Active Member
Licensed User
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);
^
 
Last edited:
Upvote 0

Bob Spielen

Active Member
Licensed User
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
B4X:
Starter.kvs.Put("tpped", Main.TpPed)
 

Attachments

  • Error22.png
    Error22.png
    11.7 KB · Views: 182
Last edited:
Upvote 0

Bob Spielen

Active Member
Licensed User
Please upload the project (File - Export as zip).
Guten Morgen!
Als Anlage.
I'm considering the possibility of replace my SQL2 structure with the Types structure.

Thank you very much for your help!
 

Attachments

  • Project_LaParma.zip
    65.7 KB · Views: 164
Last edited:
Upvote 0

Bob Spielen

Active Member
Licensed User
The type of: Main.TpPed(0).TpItem is TpItemT.
It is not an array. This line is wrong:
B4X:
Main.TpPed(0).TpItem=Array As TpItemT(ct, ct1)
It will work with:
B4X:
Main.TpPed(0).TpItem = ct


Were am I doing the mistake? Your suggestion gives me an "Array expected" error...
See image
 

Attachments

  • ArrayExpected.png
    ArrayExpected.png
    8.1 KB · Views: 164
Upvote 0

klaus

Expert
Licensed User
Longtime User
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.
 
Last edited:
Upvote 0

Bob Spielen

Active Member
Licensed User
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!
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
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)
 
Upvote 0

Bob Spielen

Active Member
Licensed User
Thats nice! You are a genius! You declared the child Type array in the parent Type !
THANK YOU VERY MUCH! SPRING STARTED NOW! HAVE STILL A NICE DAY!
 
Upvote 0

Bob Spielen

Active Member
Licensed User
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.
 
Upvote 0
Top