Gary Milne Active Member Licensed User Longtime User Aug 25, 2014 #1 I have a class that contains a Button among other things. When I Initialize a new instance of the class it Initializes the Button and sets a shared Event handler. Problem is that it does not recognize any click events on the button. If I Initialize the Button separately somewhere in the Activity (vs in the Class) then the click events are recognized. I'm new to classes so it is probably something fundamental. How do I make the Event_Handler visible to the Activity when it is Initialized within the class. I can work around it but it's not nearly as clean. Any help appreciated for a B4A newbie.
I have a class that contains a Button among other things. When I Initialize a new instance of the class it Initializes the Button and sets a shared Event handler. Problem is that it does not recognize any click events on the button. If I Initialize the Button separately somewhere in the Activity (vs in the Class) then the click events are recognized. I'm new to classes so it is probably something fundamental. How do I make the Event_Handler visible to the Activity when it is Initialized within the class. I can work around it but it's not nearly as clean. Any help appreciated for a B4A newbie.
klaus Expert Licensed User Longtime User Aug 25, 2014 #2 Without seeing what exactly you have done it's impossible to give you a concrete advice. You need to define the Click event in the Class where you can execute code. If you need an event in the calling activity you must define one and call it from the event routine in the class. In the class: Code: Private Sub btnTest_Click ' code internal to the class If SubExists(CallbackModule, EventName & "_Click") Then CallSub(CallbackModule, EventName & "_Click") End If End Sub In the Activityy: Code: Sub clsTest_Click End Sub CallbackModule, EventName are the ones you transmit in the Initialize routine for the class. Code: Dim clsTest As MyClass clsTest.Initialize(Me, "clsTest") Upvote 0
Without seeing what exactly you have done it's impossible to give you a concrete advice. You need to define the Click event in the Class where you can execute code. If you need an event in the calling activity you must define one and call it from the event routine in the class. In the class: Code: Private Sub btnTest_Click ' code internal to the class If SubExists(CallbackModule, EventName & "_Click") Then CallSub(CallbackModule, EventName & "_Click") End If End Sub In the Activityy: Code: Sub clsTest_Click End Sub CallbackModule, EventName are the ones you transmit in the Initialize routine for the class. Code: Dim clsTest As MyClass clsTest.Initialize(Me, "clsTest")