Android Question Is it possible to set implicit caller?

Alessandro71

Well-Known Member
Licensed User
Longtime User
When creating an object that raises an event, is it possible to automatically address the caller module?
In the following example, the testobject object raises an event: in the Initialize sub, I used Me to specify the current module.
Is there another way to do it, so the Initialize sub can have only the "event" parameter and not the callback one, since it will always be "Me"?
It should be possible, since the Serial library object has only "eventname" in the Initialize sub.

Main:
Sub Process_Globals
    Dim t As testobject
End Sub

Sub AppStart (Args() As String)
    Log("Hello world!!!")
    
    t.Initialize(Me, "evento")
    t.RaiseEvent
End Sub

Sub evento
    Log("evento")
End Sub


testobject:
Sub Class_Globals
    Dim mcallback As Object
    Dim mevent As String
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(callback As Object, event As String)
    mcallback = callback
    mevent = event
End Sub

Public Sub RaiseEvent
    CallSub(mcallback, mevent)
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It should be possible, since the Serial library object has only "eventname" in the Initialize sub.
It is possible when you write native libraries as the BA parameter is hidden from the IDE. You will need to pass Me.

Note that when an event is raised, the Sender keyword will hold the calling class instance.
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
It is possible when you write native libraries as the BA parameter is hidden from the IDE. You will need to pass Me.

Note that when an event is raised, the Sender keyword will hold the calling class instance.

Thank you, I knew about Sender and tested it, but in this case is not useful, since the Initialize is not an event.
Is this case a candidate for an enhancement request for Sender keyword?
 
Upvote 0
Top