Bug? Property 'tag' on ImageView (mode debug or release)

vecino

Well-Known Member
Licensed User
Longtime User
Hello, is this a bug?
Example. Release mode.
B4X:
Sub Example
  ' create a panel
  Dim p As Panel
  p.Initialize("pnItemCompo")
  p.Tag = Qt.GetInt("id")
  p.Color = Colors.Transparent
  ' add to HorizontalScrollView
  hsvComponentes.Panel.AddView( p, iCol*iAncho, iFil*iAlto, iAncho, iAlto )
  '             
  ' add viewimagen
  Dim ivImgArti As ImageView
  ivImgArti.Initialize("")
  p.AddView(ivImgArti,20,0,p.Width-40dip,p.Height-20dip)
  ivImgArti.Bitmap = img
  ivImgArti.Gravity = Gravity.FILL
'  ivImgArti.Tag=0    ' We must put a tag, because it is null. However Debug mode does have a value !!!     <---
  '
  ' add imagen OK
  Dim ivOk As ImageView
  ivOk.Initialize("")
  p.AddView(ivOk,0,0,36,36)
  ivOk.Bitmap = LoadBitmap(File.DirAssets,"dialog-apply-48.png")
  ivok.Gravity = Gravity.FILL
  ivOk.BringToFront
  ivOk.Tag=(-1)  ' Mark
  ivOk.Visible=False
End Sub

Sub pnItemCompo_Click
    Dim pp As Panel = Sender
    For Each vv As View In pp.GetAllViewsRecursive
        If vv Is ImageView Then
            If vv.Tag=(-1) Then    ' <---   Error. Tag is null in Release mode.  !!!!!!!!!!!!!
              vv.Visible = Not(vv.Visible)
            End If
        End If
    Next
End Sub
However, in Debug mode, that works well.

If I add this line:
B4X:
  ivImgArti.Tag=0    ' We must put a tag, because it is null. However Debug mode does have a value !!!    <---
The code works fine in Debug and Release mode.

B4A 5
 

vecino

Well-Known Member
Licensed User
Longtime User
Yes, I created a very condensed example.
The line:
B4X:
'    ivImgArti.Tag=0    ' I need to assign a value. Because otherwise it will be null and crash !!!
Thank You.
 

Attachments

  • Example.zip
    19.8 KB · Views: 194

sorex

Expert
Licensed User
Longtime User
that happend in 3.x & 4.x too if you don't set a tag.
 

sorex

Expert
Licensed User
Longtime User
not from B4A atleast. I guess the property doesn't exist when you don't set it that why you get this error.
 

MaFu

Well-Known Member
Licensed User
Longtime User
not from B4A atleast. I guess the property doesn't exist when you don't set it that why you get this error.
The Property exist always. But "Tag" is from type "Object" and can receive different data types (Int, String, List, Map, Type, Class, ...). Without assignment "Tag" is not initialized and has the value "Null". Therefore if you use "Tag" you should assign always a proper value.
 
Last edited:
Top