B4J Question Standard Class & Compile to Lib

Cableguy

Expert
Licensed User
Longtime User
Hi Guys,

Taking my first steps in the B4X Library creation using the Compile to Lib feature... BUT I am using a Standard Class and not a CustomView Class.
The major difference, for my case, is the callback ref that allows events to be fired in the same Module that the lib was declared and used...
So this is puzzling me... maybe its just me... but... How to get a reference of the calling Module without using Me?
Hope I make sense
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
Unless you have some special requirement I think that you are simply thinking the wrong way round. The caller passes "Me" and a handler prefix to the class . . .

B4X:
    cls.Initialize(Me, "class1")

The class remembers this and uses it to callback to the caller . . .

B4X:
Public Sub Initialize(callerModule As Object, handlerPrefix As String)
    caller = callerModule
    prefix = handlerPrefix   
End Sub

Public Sub callMe(msg As String)
    returnCall(msg)
End Sub

Private Sub returnCall(msg As String)
    If SubExists(caller, prefix & "_Ok") Then CallSub2(caller, prefix & "_Ok", msg)
End Sub

Here is a complete example . . .
 

Attachments

  • ClassExample.zip
    2.5 KB · Views: 172
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Unless you have some special requirement I think that you are simply thinking the wrong way round. The caller passes "Me" and a handler prefix to the class . . .

B4X:
    cls.Initialize(Me, "class1")

The class remembers this and uses it to callback to the caller . . .

B4X:
Public Sub Initialize(callerModule As Object, handlerPrefix As String)
    caller = callerModule
    prefix = handlerPrefix  
End Sub

Public Sub callMe(msg As String)
    returnCall(msg)
End Sub

Private Sub returnCall(msg As String)
    If SubExists(caller, prefix & "_Ok") Then CallSub2(caller, prefix & "_Ok", msg)
End Sub

Here is a complete example . . .
Thanks for taking the time...
 
Upvote 0
Top