Using 'sender' with a custom class

Mickster

Active Member
Licensed User
Longtime User
I made a class that essentially adds some features and properties to the label. I use a lot of these so I'd like to be able to target a particular instance without knowing which one was targeted.

For example

B4X:
Sub DataLabel_Click

Dim d as datalabel
d = sender
d.callSpecialMethodOfThisClass

End Sub

The actual sender in this case would be the click event of a real android label, so it doesn't have access to my methods.

What would be the best way to achieve this?
 
Last edited:

derez

Expert
Licensed User
Longtime User
A possible way to do it:
in the datalabel class make a click event sub which will call the activity that launched the datalabel, using a callsub or callsubdelayed -
B4X:
Sub Mylabel_click
If SubExists(Mmodule, "Datalabel_click") Then
  CallSub3(Mmodule, "Datalabel_click", Me, someparameter)
End If
End Sub

In the calling activity (MModule) make a sub -
B4X:
Sub Datalabel_click(D As Datalabel,[some parameter] )
D.callSpecialMethodOfThisClass 
End Sub
 
Last edited:
Upvote 0

Mickster

Active Member
Licensed User
Longtime User
(If you saw my original response, it's because I hadn't noticed you passed 'me' as a parameter)

I'll see how it does, thanks!
 
Upvote 0
Top