Hello all.
I am a development team here from Brazil, and I'm developing an application with Basic4Android for Sales Force.
What is happening is the following:
Must enter information for multiple items ordered, for it created the class itempedido with their attributes and methods, and instantiate an object ip. For each order item entered, I change the appropriate attributes of the object ip and add it to a list object, and use a table object to display.
It turns out that when adding the second item, the first item of data also change. Adding the third item, the first two are modified, and so on.
From what I understood, it seems that a list object keeps a reference to the ip in position, so if I change object attributes ip, this will be reflected in all positions of the object list.
How do I fix this? I need every position of the object list objects have different ip, because each represents a different item from an application with different products and quantities.
Have searched the forum and Google, but not found a solution.
itempedido Class
Activity
I am a development team here from Brazil, and I'm developing an application with Basic4Android for Sales Force.
What is happening is the following:
Must enter information for multiple items ordered, for it created the class itempedido with their attributes and methods, and instantiate an object ip. For each order item entered, I change the appropriate attributes of the object ip and add it to a list object, and use a table object to display.
It turns out that when adding the second item, the first item of data also change. Adding the third item, the first two are modified, and so on.
From what I understood, it seems that a list object keeps a reference to the ip in position, so if I change object attributes ip, this will be reflected in all positions of the object list.
How do I fix this? I need every position of the object list objects have different ip, because each represents a different item from an application with different products and quantities.
Have searched the forum and Google, but not found a solution.
itempedido Class
B4X:
Sub Class_Globals
Private PalmVendor As Int
Private CodigoVenda As Int
Private CodigoPro As Int
Private SeqItemVenda As Int
Private qtdVenda As Double
Private unitarioVenda As Double
Private fatorVenda As String
Private codigoIntPro As Int
Private totalLinha As Double
Private exportado As String
Private valorTabela As Double
Private nomePro As String
Private codigoConhecido As String
Private feirinha As String
Private ordemGravacao As Int
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
PalmVendor = 0
CodigoVenda = 0
CodigoPro = 0
SeqItemVenda = 0
qtdVenda = 0
unitarioVenda = 0
fatorVenda = ""
codigoIntPro = 0
totalLinha = 0
exportado = ""
valorTabela = 0
nomePro = ""
codigoConhecido = ""
feirinha = ""
ordemGravacao = 0
End Sub
Public Sub getPalmVendor() As Int
Return PalmVendor
End Sub
Public Sub setPalmVendor(nPalmVendor As Int)
PalmVendor = nPalmVendor
End Sub
Public Sub getCodigoVenda() As Int
Return CodigoVenda
End Sub
Public Sub setCodigoVenda(nCodigoVenda As Int)
CodigoVenda = nCodigoVenda
End Sub
Public Sub getCodigoPro() As Int
Return CodigoPro
End Sub
Public Sub setCodigoPro(nCodigoPro As Int)
CodigoPro = nCodigoPro
End Sub
Public Sub getSeqItemVenda() As Int
Return SeqItemVenda
End Sub
Public Sub setSeqItemVenda(nSeqItemVenda As Int)
SeqItemVenda = nSeqItemVenda
End Sub
Public Sub getQtdVenda() As Double
Return qtdVenda
End Sub
Public Sub setQtdVenda(nqtdVenda As Double)
qtdVenda = nqtdVenda
End Sub
Public Sub getCodigoConhecido() As String
Return codigoConhecido
End Sub
Public Sub setCodigoConhecido(ccodigoConhecido As String)
codigoConhecido = ccodigoConhecido
End Sub
Public Sub getCodigoIntPro() As Int
Return codigoIntPro
End Sub
Public Sub setCodigoIntPro(ncodigoIntPro As Int)
codigoIntPro = ncodigoIntPro
End Sub
Public Sub getExportado() As String
Return exportado
End Sub
Public Sub setExportado(cexportado As String)
exportado = cexportado
End Sub
Public Sub getFatorVenda() As String
Return fatorVenda
End Sub
Public Sub setFatorVenda(cfatorVenda As String)
fatorVenda = cfatorVenda
End Sub
Public Sub getFeirinha() As String
Return feirinha
End Sub
Public Sub setFeirinha(cfeirinha As String)
feirinha = cfeirinha
End Sub
Public Sub getNomePro() As String
Return nomePro
End Sub
Public Sub setNomePro(cnomePro As String)
nomePro = cnomePro
End Sub
Public Sub getOrdemGravacao() As Int
Return ordemGravacao
End Sub
Public Sub setOrdemGravacao(nordemGravacao As Int)
ordemGravacao = nordemGravacao
End Sub
Public Sub getTotalLinha() As Double
Return totalLinha
End Sub
Public Sub setTotalLinha(ntotalLinha As Double)
totalLinha = ntotalLinha
End Sub
Public Sub getUnitarioVenda() As Double
Return unitarioVenda
End Sub
Public Sub setUnitarioVenda(nunitarioVenda As Double)
unitarioVenda = nunitarioVenda
End Sub
Public Sub getValorTabela() As Double
Return valorTabela
End Sub
Public Sub setValorTabela(nvalorTabela As Double)
valorTabela = nvalorTabela
End Sub
Activity
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.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim tbVendaItens As Table
Dim thVendas As TabHost
Dim lpedidoitens As List
Dim ip As itempedido
...
...
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("T9_Vendas_Manut")
ip.Initialize
...
...
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
...
...
...
Sub btAdd_Click
If (edCodigoConhecido.Text <> "") AND _
(edQtdVenda.Text <> "") AND _
(edUnitarioVenda.Text <> "") Then
ip.setQtdVenda(edQtdVenda.Text)
ip.setUnitarioVenda(edUnitarioVenda.Text)
ip.setTotalLinha( pedidoitens.getQtdVenda() * ip.getUnitarioVenda())
If ckbFator.Checked Then
ip.setFatorVenda("S")
Else
ip.setFatorVenda("N")
End If
If ip.getOrdemGravacao() = 0 Then
ip.setOrdemGravacao(lpedidoitens.Size+1)
lpedidoitens.Add(ip)
Else
lpedidoitens.Set((ip.getOrdemGravacao-1),ip)
End If
MontaTabelaItens
ip.Initialize
ApagaItensView
Else
Msgbox("Dados incompletos.","ATENÇÃO")
End If
End Sub