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

Discussion in 'Bugs & wishlist' started by vecino, Jul 14, 2015.

  1. vecino

    vecino Well-Known Member Licensed User

    Hello, is this a bug?
    Example. Release mode.
    Code:
    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=(-1Then    ' <---   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:
    Code:
    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Can you upload a small project that demonstrates this issue?
     
  3. vecino

    vecino Well-Known Member Licensed User

    Yes, I created a very condensed example.
    The line:
    Code:
    '    ivImgArti.Tag=0    ' I need to assign a value. Because otherwise it will be null and crash !!!
    Thank You.
     

    Attached Files:

  4. sorex

    sorex Expert Licensed User

    that happend in 3.x & 4.x too if you don't set a tag.
     
  5. vecino

    vecino Well-Known Member Licensed User

    Thank You :)
    It is B4A v5
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    You need to explicitly set the tag value before you use it.
     
  7. vecino

    vecino Well-Known Member Licensed User

    Thanks, then, is not a bug?
     
  8. sorex

    sorex Expert Licensed User

    not from B4A atleast. I guess the property doesn't exist when you don't set it that why you get this error.
     
  9. MaFu

    MaFu Well-Known Member Licensed User

    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: Jul 16, 2015
  10. vecino

    vecino Well-Known Member Licensed User

    Thanks to all :)
     
  11. sorex

    sorex Expert Licensed User

    @MaFu : no kidding, I thought is was just a string.
     
Loading...