Java Question subExists, raiseEvent

Semen Matusovskiy

Well-Known Member
Licensed User
Hi, guys --

I obviously something do not understand.
To demonstrate my troubles I created following "library"

B4X:
package b4a.SM.Test;

import anywheresoftware.b4a.BA;

@BA.Version (1.00f)
@BA.ShortName ("smTest")
@BA.ActivityObject

public class smTest
    {
    public void Initialize (BA ba, String eventName)
        {
        if (ba.subExists (eventName))
            { BA.LogInfo ("Yes"); }
        else
            {
            BA.LogInfo ("No");
            }
        }
    }

B4A:
B4X:
Sub Process_Globals
End Sub

Sub Globals
     Private smTest                                                              As smTest   
End Sub

Sub Activity_Create (FirstTime As Boolean)
    smTest.Initialize ("_eventname")   
End Sub

Sub eventName   
    Log ("Sub eventName")
End Sub

Why subExists returns "No", unlike inside main.java
B4X:
public static String  _eventname() throws Exception{
 //BA.debugLineNum = 31;BA.debugLine="Sub eventName";
 //BA.debugLineNum = 32;BA.debugLine="Log (\"Sub eventName\")";
anywheresoftware.b4a.keywords.Common.Log("Sub eventName");
 //BA.debugLineNum = 33;BA.debugLine="End Sub";
return "";
}
 

monic

Active Member
Licensed User
Longtime User
I hope this helps https://www.b4x.com/android/forum/t...iseevent-from-inline-java-code.50161/#content

In your java code it would be super easy to raise the event and catch it in the sub.

Initial and then...

B4X:
if (ba.subExists(smTest.eventName + "_eventName")) {
    ba.raiseEvent(this, smTest.eventName + "_eventName", "Test");
   } else {
    BA.LogError("event sub does not exist: " + smTest.eventName);
   }

B4X:
Sub eventName(a as string)
Log(a) '<!-- test
End sub

hopefully the logic of the code is use full for you.
 

Semen Matusovskiy

Well-Known Member
Licensed User
Thanx.
Inline java is another question (java code here is inserted into activity class).
In case of library there are two different classes.
 

Semen Matusovskiy

Well-Known Member
Licensed User
Thanx, Erel. Underscore is last about which I thought :) Now a test works, hope this will fix troubles in real library.
 
Top