Something has changed over the years
I am revisiting my Basic scripting interpreter that worked fine back in 2012. I have changed nothing in the B4A app or the library but it no longer runs.
Now when an event is raised in my BasicIDE library I get this exception in the Logs
Unexpected event (missing RaiseSynchronousEvents): setvisible
Check the unfiltered logs for the full stack trace.
CallHostSub : setvisible returned Null at line 219
SetVisible is the B4A Sub being called from the library but this happens whichever Sub being called as an event.
The code raising the event in the library is as follows. This used to work but now doesn't so I guess the event mechanism has changed in the last six years.
It looks like raiseEvent2 is returning null but this event is not being raised during Activity_Create but during normal program operation
Any ideas on what I should change to make this work again?
I am revisiting my Basic scripting interpreter that worked fine back in 2012. I have changed nothing in the B4A app or the library but it no longer runs.
Now when an event is raised in my BasicIDE library I get this exception in the Logs
Unexpected event (missing RaiseSynchronousEvents): setvisible
Check the unfiltered logs for the full stack trace.
CallHostSub : setvisible returned Null at line 219
SetVisible is the B4A Sub being called from the library but this happens whichever Sub being called as an event.
B4X:
Sub SetVisible(name As String, visible As String)
Dim v As View
v = viewmap.Get(name)
If v.IsInitialized Then
v.visible = visible
End If
End Sub
The code raising the event in the library is as follows. This used to work but now doesn't so I guess the event mechanism has changed in the last six years.
It looks like raiseEvent2 is returning null but this event is not being raised during Activity_Create but during normal program operation
B4X:
private String callhostsub(String sub, Object[] args, boolean runonguithread)
{
try
{
sub = sub.toLowerCase();
if (args == null)
args = new String[0];
if (!ba.subExists(sub))
{
saveerror("CallHostSub : Sub " + sub + " not found!");
return null;
}
// we need to check the thread we are on at event or call time
// because we could be newed on main thread and invoked on another
if (!runonguithread || (Thread.currentThread() == guithread))
{
String ret;
// use raiseEvent2 to let it run during Activity_Create
ret = (String) ba.raiseEvent2(this, true, sub, false, args);
// raiseEvent returns null during Activity_Create
if (ret == null)
{
// unlikely to get this now but left in just in case
String msg = "CallHostSub : " + sub + " returned Null";
saveerror(msg);
Log.e("B4A", msg + " at line " + linenum);
}
return ret;
}
TaskId += 1;
ba.raiseEventFromDifferentThread(this, this, TaskId, sub, false, args);
} catch (Exception e)
{
String msg = "CallHostSub : " + sub + " - " + e.toString() + " - " + e.getMessage();
saveerror(msg);
Log.e("B4A", msg + " at line " + linenum);
Log.e("B4A", "", e); // stack trace
}
return "";
}