label.tag reading problem

Ramirez

Member
Licensed User
Longtime User
Hello.

I don't understand what is the problem
I adapted the code of TableExample tutorial and write this code:

B4X:
Sub AjoutLigne(valeur() As String, ind As Int)
   If valeur.Length<>2 Then Return
   Dim cell As Label            
   'First column
   cell.Initialize("cellule")
   cell.Text=valeur(0)
   cell.Gravity=Gravity.LEFT
   cell.TextSize=18
   cell.TextColor=Colors.Black
   cell.Color=Colors.White
   Dim ligneColonne As coordonnee
   ligneColonne.Initialize
   ligneColonne.col = 0
   ligneColonne.row = numeroDeLigne
   ligneColonne.clef = ind
   cell.Tag = ligneColonne
   Msgbox("row col clef" & CRLF & ligneColonne.row & "    " & ligneColonne.col & "    " & ligneColonne.clef,"lignecolonne")
   Msgbox(cell.Tag,"celltag")
   panTable.AddView(cell, 0, 40 * numeroDeLigne, 400, 38)
   'sencond column
   cell.Initialize("cellule")
   cell.Text=valeur(1)
   cell.Gravity=Gravity.CENTER_HORIZONTAL
   cell.TextSize=18
   cell.TextColor=Colors.Black
   cell.Color=Colors.White
   ligneColonne.col = 1
   ligneColonne.row = numeroDeLigne
   ligneColonne.clef = ind
   cell.Tag=ligneColonne
   Msgbox("row col clef" & CRLF & ligneColonne.row & "    " & ligneColonne.col & "    " & ligneColonne.clef,"lignecolonne")
   Msgbox(cell.Tag,"celltag")
   panTable.AddView(cell, 400, 40 * numeroDeLigne, 80, 38)
   numeroDeLigne=numeroDeLigne+1
   panTable.Height=numeroDeLigne*40
      
End Sub

Sub Cellule_Click
   Dim ligneColonne As coordonnee
   ligneColonne.Initialize
   Dim l As Label
   l = Sender
   ligneColonne=l.Tag
   modifSaisie = ligneColonne.clef
   Msgbox("row col clef" & CRLF & ligneColonne.row & "    " & ligneColonne.col & "    " & ligneColonne.clef,"lignecolonne")
   Msgbox(l.Tag,"ltag")
   End Sub

As you can see, I put some messagebox to know the value of some data.
Only 2 row of 2 column for this example.

During the ajoutligne running sub, the data shown are:


First row, first column
row col clef : 0.0.1
cell.Tag : init ok, value clef 1, col 0, row 0

First row, second column
row col clef : 0.1.1
cell.Tag : init ok, value clef 1, col 1, row 0

Second row, first column
row col clef : 1.0.2
cell.Tag : init ok, value clef 2, col 0, row 1

second row, second column
row col clef : 1.1.2
cell.Tag : init ok, value clef 2, col 1, row 1

etc...

All the data seem correct (it's normal that clef is increase)

But during the Cellule_Click sub, the data are:
First row, first column
row col clef : 0.1.1
cell.Tag : init ok, value clef 1, col 1, row 0

First row, second column
row col clef : 0.1.1
cell.Tag : init ok, value clef 1, col 1, row 0

Second row, first column
row col clef : 1.1.2
cell.Tag : init ok, value clef 2, col 1, row 1

second row, second column
row col clef : 1.1.2
cell.Tag : init ok, value clef 2, col 1, row 1

As you can see, the column number is always 1, I cannot have the good column number.

Do you see where is my mistake please ?
 

klaus

Expert
Licensed User
Longtime User
Il serait plus facile pour nous si tu mettais le projet en tant que fichier zip car nous pourrions tester le programme et touver beaucoup plus facilement le problème.

Au premier coup d'oeuil, il manque un Dim Cell As Label juste après la ligne 'second label.
B4X:
panTable.AddView(cell, 0, 40 * numeroDeLigne, 400, 38)
'sencond column
[COLOR=red]Dim cell As Label[/COLOR]    
cell.Initialize("cellule")
cell.Text=valeur(1)
Sinon cell est le même objet pour les deux donc ayant les mêmes paramètres.

Meilleures salutations.
 
Upvote 0

Ramirez

Member
Licensed User
Longtime User
Rhaaaa joie, un Francophone !!! :D

Je me débrouille en Anglais, mais j'ai toujours peur de ne pas être compris.

En ce qui concerne la réponse que tu me donnes, je ne comprends pas trop: en effet, Cell est déclaré en tant que label plus haut, pour la première colonne.

Il faut le déclarer à chaque utilisation ?

En ce qui concerne mon programme, je veux bien le partager, mais c'est plus que brouillon et encore pas assez fonctionnel. Si tu veux jeter un oeil, n'hésite pas, mais attention aux yeux qui coulent ;)
 

Attachments

  • prog.zip
    21.8 KB · Views: 190
Upvote 0

Ramirez

Member
Licensed User
Longtime User
I try to make 2 label, one for each column, (and don't forget to declare the both :D ) but the result is the same.
 
Upvote 0

Ramirez

Member
Licensed User
Longtime User
I find the solution !

It's not the cell that I forget to declare, but the lignecolonne !

I don't know exactly why, but now that works
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Yes, you need to declare both with Dim!
You need a different instance of both objectsfor each column, otherwise changing a value stes it to all objects with the same instance because they all have the same reference.

Best regards.

Tu dois déclarer les deux avec un Dim.
Tu as besoin d'une nouvelle instance pour chacun des objets dans chaque colonne. Sinon, en changeant une valeur, elle est reportée sur tous les objets avec la même instance puisque la référence est la même.

Meilleures salutations.
 
Upvote 0
Top