Android Question Class - Sub Initialize without parameters CallBack and EventName

Sergio Haurat

Active Member
Licensed User
Longtime User
I have a class to which I would really prefer not to pass the Callback and EventName parameters. The example is just illustrative.

Real example
B4X:
'In a Class
#Event: Error (Msg As String)
Sub Class_Globals
  Private mCallBack As Object
  Private mEvent As String
End Sub

Public Sub Initialize(CallBack As Object, EventName As String)
    mCallBack = CallBack
    mEvent = EventName
End Sub

'In B4XPage
Sub Class_Globals
    Private obj As objClass
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    obj.Initialize(Me, "CustomEventName")
End Sub

Private Sub CustomEventName_Error(Msg As String)
  'Error handling
End Sub

What I need (if this is possible), the class name is 'ClassTestName'
B4X:
#Event: Error (Msg As String)
Sub Class_Globals
  Private mCallBack As Object
  Private mEvent As String
End Sub

Public Sub Initialize()
    mCallBack = Me.Parent
    mEvent = Me.Parent.NameOfClass 'Return ClassTestName
End Sub

Private Sub ClassTestName_Error(Msg As String)
  'Error handling
End Sub
 

Sagenut

Expert
Licensed User
Longtime User
I think that this it's not possible, because the Class does not belong to a specific Activity or Pages.
So it's needed to pass the Callback if you need to raise events.
 
Upvote 0
Top