iOS Question [Solved] Problem - Event target instance was released (event handling in classes)

yonson

Active Member
Licensed User
Longtime User
First off a massive thank you for Erel in developing B4i which is in every way an improvement on the previous tool we were using. I've just been going through the tutorials and putting a few projects together and have a quick query regarding event handling in a class.

I have created a class which I'm using to hold a configurable panel (to hold a mix of views based on the input parameters). I've stripped back all the code to something very simple. Here is the relevant code:-

B4X:
'Class module
Sub Class_Globals
    Dim pnl As Panel
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(text As String, x As Int, y As Int, size As Int)
        pnl.Initialize("PanelButton")  
End Sub

Sub render As Panel
    Return pnl
End Sub

Sub PanelButton_Click
    Log("PanelButton was Clicked")
End Sub


My problem is that whilst the views etc are rendered fine, when I click on the panel, I don't get the log message, but instead get this code:-

"Event target instance was released: btn_click"

However, if I remove the Sub PanelButton_Click completely, then it just closes with no log entry at all.

Sure it will be a simple explanation but I'm looking to understand why this isn't working as expected. Do I need to move the call into another module?

Many thanks!
 
Last edited:

yonson

Active Member
Licensed User
Longtime User
thanks Erel - what is the correct approach - i.e. where should the event handler be placed in this example?

here is a sample code that calls the class:-

B4X:
' sample class name
Dim p As PanelButton 
p.Initialize("hello there",0,0,25%x)
Page1.RootPanel.AddView(p.render,0,0,50%x,50%x)
 
Last edited:
Upvote 0

yonson

Active Member
Licensed User
Longtime User
thats great thanks Erel - the 2nd option works fine, my understanding is that so long as a reference is kept in the tag then it persists long enough for the click action to work.

Thanks for clearing that up
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
my understanding is that so long as a reference is kept in the tag then it persists long enough for the click action to work
It is more accurate to say that as long as there is a reference to the view (and there is one because you added the view to another view) then the reference to the tag will be kept.
 
Upvote 0
Top