Semen Matusovskiy Well-Known Member Licensed User Oct 7, 2018 #1 Hi, guys -- I obviously something do not understand. To demonstrate my troubles I created following "library" Code: Copy 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: Copy 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: Copy 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 ""; }
Hi, guys -- I obviously something do not understand. To demonstrate my troubles I created following "library" Code: Copy 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: Copy 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: Copy 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 Oct 7, 2018 #2 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: Copy if (ba.subExists(smTest.eventName + "_eventName")) { ba.raiseEvent(this, smTest.eventName + "_eventName", "Test"); } else { BA.LogError("event sub does not exist: " + smTest.eventName); } Code: Copy Sub eventName(a as string) Log(a) '<!-- test End sub hopefully the logic of the code is use full for you.
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: Copy if (ba.subExists(smTest.eventName + "_eventName")) { ba.raiseEvent(this, smTest.eventName + "_eventName", "Test"); } else { BA.LogError("event sub does not exist: " + smTest.eventName); } Code: Copy 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 Oct 7, 2018 #3 Thanx. Inline java is another question (java code here is inserted into activity class). In case of library there are two different classes.
Thanx. Inline java is another question (java code here is inserted into activity class). In case of library there are two different classes.
Erel B4X founder Staff member Licensed User Longtime User Oct 8, 2018 #4 You shouldn't add the underscore. Code: Copy smTest.Initialize ("eventname")
Semen Matusovskiy Well-Known Member Licensed User Oct 8, 2018 #5 Thanx, Erel. Underscore is last about which I thought Now a test works, hope this will fix troubles in real library.
Thanx, Erel. Underscore is last about which I thought Now a test works, hope this will fix troubles in real library.