Bug? MouseEvent problem when converted as object

Discussion in 'B4J Bugs & Wishlist' started by jmon, May 22, 2015.

  1. jmon

    jmon Well-Known Member Licensed User


    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:
    Sub AppStart (Form1 As Form, Args() As String)
        MainForm = Form1
    "Main"'Load the layout file.
    End Sub

    Sub btn_MouseClicked (EventData As MouseEvent)   
    "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?


    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    You will need to change your code to:
    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.
    Phayao and jmon like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice