Trying to build a generic timer class with parameters

melamoud

Active Member
Licensed User
Longtime User
hi, trying to build something and it is not wokring, (the callbackfunc is not been called) help!
B4X:
' this is the TimerWithParam class module
'Class module

Sub Class_Globals
   Dim param As Object
   Dim interval As Long
   Dim cb As Object
   Dim t As Timer
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize (P As Object, inter As Long, CallBack As Object)
   param = P
   interval = inter
   cb = CallBack
   Log ("@@:Timer is set:" & param)
   t.Initialize("TWP",interval)
End Sub

Public Sub SetInterval(inter As Long)
   t.interval = inter
End Sub
Public Sub GetInterval As Long
   Return interval
End Sub

Public Sub Enable(flag As Boolean)
   t.Enabled = flag
End Sub

Sub TWP_Tick
   Log ("@@:Tick:" & param)
   CallSub3(cb,"callBackFunc",Me,param)
   t.Enabled = False
End Sub



' this is the callback class
'Class module
Sub Class_Globals
   
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
   Log ("@@ in init")
End Sub

Public Sub callBackFunc(t As TimerWithParam,param As String)
   Log ("@@ in callbackFun")
   ToastMessageShow("called back from timer:" & param,False)
End Sub


' this is the main (activity)
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")
   If (FirstTime) Then
      Dim t As TimerWithParam
      Dim cb1 As callMe
      t.Initialize("Test 1",2000,cb1)
      t.Enable(True)
    End If
   
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub
 
Top