Bug? IDE warns the variables as uninitialized

winiha

Member
Licensed User
hi
i use a sub in code module to loadlayout to my activity
but when I declare them, the ide warns the objects of layout as uninitialized although it complies it correctly
please make it to recognize this kind of vars as of ones not to be initialized
B4X:
Sub AddLayoutToCustomView(cv As CustomListView,Layout As String) As Panel
    Dim h As Int=0
    Dim pnl As Panel
    pnl.Initialize(Layout)
    pnl.Width = 100%x
    pnl.Height = 100%y
    pnl.LoadLayout(Layout)
    For Each vn As View In pnl.GetAllViewsRecursive
        If vn.top+vn.Height>h And vn.Visible Then
            h=vn.Height+vn.top
        End If
    Next
    cv.Add(pnl,h,"0",False)
    Return pnl
End Sub

upload_2017-12-9_17-42-30.png
 

Cableguy

Expert
Licensed User
Longtime User
It complains because your panel event has the same name as the layout file, and it's being passed to the sub as a string.
Since you have full control over thar, I would either change the sub signature to something like:
B4X:
Sub AddLayoutToCustomView(EventName as String, cv As CustomListView,Layout As String) As Panel

Or change the code to :
B4X:
Sub AddLayoutToCustomView(cv As CustomListView,Layout As String) As Panel
    Dim h As Int=0
    Dim pnl As Panel
    Dim EventName as string = cv
    pnl.Initialize(EventName)
    pnl.Width = 100%x
    pnl.Height = 100%y
    pnl.LoadLayout(Layout)
    For Each vn As View In pnl.GetAllViewsRecursive
        If vn.top+vn.Height>h And vn.Visible Then
            h=vn.Height+vn.top
        End If
    Next
    cv.Add(pnl,h,"0",False)
    Return pnl
End Sub
 
Last edited:

winiha

Member
Licensed User
As the worst state, suppose we change to
B4X:
pnl.Initialize("")
but the problem is remained yet!
 

Cableguy

Expert
Licensed User
Longtime User
how many layout variants do you use to populate your listview?
Usually one uses just a single layout, and load the diferente info into it, so I'm thinking you couse instead of passing the layout filename as string, which seems to be the real issue here, you could set a select case given a "LayoutNumber" in the constructer...

B4X:
Sub AddLayoutToCustomView(EventName as String, cv As CustomListView,Layout Number As int) As Panel
    Dim h As Int=0
    Dim pnl As Panel
    pnl.Initialize(EventName)
    pnl.Width = 100%x
    pnl.Height = 100%y
    Select LayoutNumber
         Case 0  
               pnl.LoadLayout("Layout0")
        Case 1  
               pnl.LoadLayout("Layout1")
       ......
    End Select
    For Each vn As View In pnl.GetAllViewsRecursive
        If vn.top+vn.Height>h And vn.Visible Then
            h=vn.Height+vn.top
        End If
    Next
    cv.Add(pnl,h,"0",False)
    Return pnl
End Sub
 

Cableguy

Expert
Licensed User
Longtime User
can you set up a small project that demonstrates this issue? (or your current project if possible)
 
Top