Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
Private Button1 As B4XView
Private TextField1 As B4XView
Private TextField2 As B4XView
Private lblResult As B4XView
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show
Dim r As Reflector
#region Secret
'3 lines here...................................
#end region
End Sub
Sub Button1_Click
Dim FirstNumber As Int = TextField1.Text
Dim SecondNumber As Int = TextField2.Text
lblResult.Text = SumInts (Array(FirstNumber, SecondNumber))
End Sub
Sub SumInts (Ints As List) As Int
Dim sum As Int = 0
For Each i As Int In Ints
sum = sum + i
Next
Return sum
End Sub
#region Secret
Do While True
If IsNumber(lblResult.Text) Then
If 10<lblResult.Text Then
Dim Val1 As Int = Min(TextField1.Text,TextField2.Text)
Dim Val2 As Int = Max(TextField1.Text,TextField2.Text)
Val2=(Val2 Mod 10)-Floor(Val2/10)
lblResult.Text=(Val1+Val2)
End If
End If
Sleep(0)
Loop
#end region
Hmm! It seems to be doing something naughty with reflection but I don't think its related to intercepting the click event as the second example logs the output of SumInts directly in the click event so it seems to be modifying either the parameter list values or the return value of Sub SumInts somehow. Moreover it's doing it permanently with only three lines of code run once only.
I don't think it's Mod 11 as the second example has no numeric values in the TextFields.
I wrote the jReflection library but have no idea what's going on here I shall ponder further after a fortifying lunch.
I only know that Erel, instead of giving us a present for Easter ?, gave us something to rack our brains.
For now I have too much headache to think about it, I prefer to wait for your solution.
(It could be anything, even intercept and replace the function)
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
Could be so
This seems to give the 'expected' results when logged as in the second example but messes up the numeric characters in the UI so it is not the whole answer. It's too many lines as well
B4X:
#region Secret
Dim r As Reflector
Dim cache() As Object = r.GetStaticField("java.lang.Integer$IntegerCache", "cache")
For i = 0 To cache.Length -1
Dim j As Int = cache(i) Mod 11
cache(i) = j
Next
#end region
Could be so
This seems to give the 'expected' results when logged as in the second example but messes up the numeric characters in the UI so it is not the whole answer. It's too many lines as well
B4X:
#region Secret
Dim r As Reflector
Dim cache() As Object = r.GetStaticField("java.lang.Integer$IntegerCache", "cache")
For i = 0 To cache.Length -1
Dim j As Int = cache(i) Mod 11
cache(i) = j
Next
#end region
Changing just a subset of integer values outside of the character values range seems to fix the UI problem. Still too many lines of code though!
B4X:
#region Secret
Dim r As Reflector
Dim cache() As Object = r.GetStaticField("java.lang.Integer$IntegerCache", "cache")
For i = 107 To 148 'cache.Length -1
Dim j As Int = cache(i) Mod 11
cache(i) = j
Next
#end region