B4J Question Is it possible to call Sub Pane1_MouseClicked (EventData As MouseEvent) recursively?

oleg_

Member
Licensed User
Hello everyone!

I'm wondering if it's possible to call Sub Pane1_MouseClicked (EventData As MouseEvent) recursively?

Here is a small experimental fragment. It doesn't make much sense. Just to understand if this is possible in principle?

If this is still possible, then please tell me what needs to be changed in my code so that the Sub Pane1_MouseClicked (EventData As MouseEvent) subroutine could call itself and pass the left mouse button press as a parameter.

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Pane1 As B4XView
    Private PrimaryButtonPressed As MouseEvent
End Sub

Public Sub Initialize
    'PrimaryButtonPressed.Initialize   ?????????????
    'MouseEvent.Initialize             ?????????????
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

Private Sub Pane1_MouseClicked (EventData As MouseEvent)
    If EventData.PrimaryButtonPressed Then
        Log ("Pane cicked with left button")
    Else
        Log ("Pane cicked with right button")
        Pane1_MouseClicked (PrimaryButtonPressed )
    End If
End Sub
Waiting for debugger to connect...
Program started.
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
Pane cicked with left button
Pane cicked with right button
Error occurred on line: 26 (B4XMainPage)
java.lang.RuntimeException: Object should first be initialized (MouseEvent).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:49)
 

Attachments

  • 01.zip
    2.9 KB · Views: 121

Brian Dean

Well-Known Member
Licensed User
Longtime User
Make the following change (correction) to your code . . .
B4X:
Private Sub Pane1_MouseClicked (EventData As MouseEvent)
    If EventData.PrimaryButtonPressed Then
        Log ("Pane cicked with left button")
    Else
        Log ("Pane cicked with right button")
        Pane1_MouseClicked (EventData )        '<====  CHANGE THIS LINE
    End If
End Sub

You now get a stack overflow, of course.
 
Upvote 0

oleg_

Member
Licensed User
Thank you, Brian.
I just needed to understand the principle of operation.
Now it works and that's good.
 
Upvote 0
Top