B4J Question [ABMaterial] Event on Class for ABMTable not always passed to page_parseevent

incendio

Well-Known Member
Licensed User
Longtime User
Hello,

I made a Class for ABMTable and found that if a variable type of ABMTable not passed to Sub Initialize in class declaration, will made click event didn't passed to a Sub Page_ParseEvent.

Here are the codes that won't pass click event
B4X:
Sub Initialize(page As ABMPage,Handler As String, Headers() As String) As ABMTable
    Private AbTbl As ABMTable
    AbTbl.Initialize(page, Handler, False, False, True, TblTheme)
    AbTbl.SetHeaders(Headers)
    AbTbl.SetColumnDataFields(Headers)
    AbTbl.IsResponsive = True
   
    Private HeadThemes As List
    HeadThemes.Initialize    
    For i = 0 To Headers.Length - 1
        HeadThemes.Add(TblHeaderTheme)
    Next
    AbTbl.SetHeaderThemes(HeadThemes)
   
    AbTbl.IsBordered = True
    Tbl = AbTbl
    Log("initialize")
    Return AbTbl
End Sub

If change those codes to this
B4X:
Sub Initialize(page As ABMPage,AbTbl As ABMTable,Handler As String, Headers() As String) As ABMTable
   AbTbl.Initialize(page, Handler, False, False, True, TblTheme)
   AbTbl.SetHeaders(Headers)
   AbTbl.SetColumnDataFields(Headers)
   AbTbl.IsResponsive = True
   
   Private HeadThemes As List
   HeadThemes.Initialize   For i = 0 To Headers.Length - 1
     HeadThemes.Add(TblHeaderTheme)
   End If
   Next
   AbTbl.SetHeaderThemes(HeadThemes)
   AbTbl.SetColumnVisible(VisibilityCol)
   
   AbTbl.IsBordered = True
   Tbl = AbTbl
   Log("initialize")
   Return AbTbl
End Sub

Noticed that, now AbTbl as type of ABMTable passed in Sub Initialize & with this codes click event passed to a Sub Page_ParseEvent.

Just curious why this is happen cause on other class for ABMInput, no need to pass a variable type ABMInput & events passed correctly to Sub Page_ParseEvent.
 

alwaysbusy

Expert
Licensed User
Longtime User
Just tested out the new proposed system from https://www.b4x.com/android/forum/t...tion-of-complex-components.83934/#post-531901 with this:
B4X:
'Class module
Sub Class_Globals
   Public AbTbl As ABMTable ' need to be public
   
   Private ABM As ABMaterial 'ignore
     
   Private TargetPage As ABMPage
   Private ObjectId As String
End Sub

' new part, we give the class it's own ParseEvent method
public Sub ParseEvent(params As Map)
   Dim eventName As String = params.Get("eventname")
   Dim eventParams() As String = Regex.Split(",",params.Get("eventparams"))
   
   ' Important! Here we remove the 'parent' part, so we can re-use the this component, as the events will have the same name
   ' e.g. myTopBar2aBtn1_Clicked will become Btn1_Clicked
   eventName = eventName.SubString(ObjectId.Length)
   
   If SubExists(Me, eventName) Then
     params.Remove("eventname")
     params.Remove("eventparams")
     Select Case params.Size
       Case 0
         CallSub(Me, eventName)
       Case 1
         CallSub2(Me, eventName, params.Get(eventParams(0)))
       Case 2
         If params.get(eventParams(0)) = "abmistable" Then
           Dim PassedTables As List = ABM.ProcessTablesFromTargetName(params.get(eventParams(1)))
           CallSub2(Me, eventName, PassedTables)
         Else
           CallSub3(Me, eventName, params.Get(eventParams(0)), params.Get(eventParams(1)))
         End If
       Case Else
         ' cannot be called directly, to many param
         CallSub2(Me, eventName, params)
     End Select
   End If
End Sub

'Initializes the object. You can add parameters to this method if needed.
public Sub Initialize(page As ABMPage, id As String, Headers() As String)
   TargetPage = page
   ObjectId = id
   AbTbl.Initialize(TargetPage, ObjectId & "tbl", False, False, True, "") ' here also we need to have a 'fixed' part of the id to receive the events
   AbTbl.SetHeaders(Headers)
   AbTbl.SetColumnDataFields(Headers)
   AbTbl.IsResponsive = True
   
   AbTbl.EventHandler = Me ' NEW
   
   Private HeadThemes As List
   HeadThemes.Initialize
   For i = 0 To Headers.Length - 1
     HeadThemes.Add("")
   Next
   AbTbl.SetHeaderThemes(HeadThemes)
   
   AbTbl.IsBordered = True   
End Sub

Sub tbl_Clicked(PassedRowsAndColumns As List)
   Log("Clicked")
End Sub

In ConnectPage()
B4X:
   ...
   Dim myTbl As tblClass
   myTbl.Initialize(page, "mytbl", Array As String("col 1", "col 2", "col 3"))
   myTbl.AbTbl.AddRow("uniqueId1", Array As String("1", "2", "3"))
   myTbl.AbTbl.SetRowThemes(Array As String("", "", ""))
   page.Cell(4,1).AddComponent(myTbl.AbTbl)
   ...

And I got the Clicked event in the class so it looks promising...
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…