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"

Code:
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:
Code:
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
Code:
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 "";
}
 
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...

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

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

hopefully the logic of the code is use full for you.
 
Thanx.
Inline java is another question (java code here is inserted into activity class).
In case of library there are two different classes.
 
Thanx, Erel. Underscore is last about which I thought :) Now a test works, hope this will fix troubles in real library.
 
Back
Top