Bug? MouseEvent problem when converted as object

jmon

Well-Known Member
Licensed User
Longtime User
Hello,

I encountered a problem today, very easy to reproduce.

I'm trying to pass a mouseEvent object through an intermediary function that will call a CallSub. I get a crash, that says that the receiving event doesn't match signature:

This is the code:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Main") 'Load the layout file.
    MainForm.Show       
End Sub

Sub btn_MouseClicked (EventData As MouseEvent)   
    CallEventCustom("myBtn_Clicked", EventData) '<Calling a custom call sub function, try to pass the mouseevent
End Sub

Private Sub CallEventCustom(EventName As String, Argument As Object)
    CallSub2(Me, EventName, Argument)'<Calling a custom call sub function
End Sub

Sub myBtn_Clicked(EventData As MouseEvent)'<crash here!
    Log($"Mouseclicks : ${EventData.ClickCount}"$)
End Sub

I've included an example. What is the problem there?

Thanks.
jmon.
 

Attachments

  • MouseEventCallProblem.zip
    1.4 KB · Views: 315

Erel

B4X founder
Staff member
Licensed User
Longtime User
You will need to change your code to:
B4X:
Sub myBtn_Clicked(EventDataObj As Object)
   Dim EventData As MouseEvent = EventDataObj
   Log($"Mouseclicks : ${EventData.ClickCount}"$)
End Sub
MouseEvent is a wrapped object. When you convert it to Object, the compiler unwraps it automatically.

Later when you call the second sub with CallSub the compiler cannot know that it needs to wrap it again so you get the error.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…