iOS Question Timer inside a Class

Discussion in 'iOS Questions' started by narek adonts, Mar 13, 2015.

  1. narek adonts

    narek adonts Well-Known Member Licensed User

    Hi,

    I am trying to create a Class.
    When adding a timer in Class_Globals the timer doesnt ticking. So the event Timer_tick is not fired.

    Can somebody help me please.

    Narek
     
  2. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    Hi.
    I think that you cannot handle event in class.
    try to handle in module only
     
  3. narek adonts

    narek adonts Well-Known Member Licensed User

    I didnt understood.
    The following code is inside a Class

    Code:
    Sub Class_Globals
        
    Dim tmrShow As Timer
       
    End Sub


    Public Sub Initialize(eventName As String, Inter As Int,color As Int,Receiver As Panel)
       
        tmrShow.Initialize(
    "tmrShow",Inter)

        tmrShow.Enabled=
    True
        pnlReceiver=Receiver
        CircleColor=color
        EventStr=eventName
        cInterval=Inter
       
    End Sub

    Private Sub TmrShow_Tick
    Log("tick")
    End Sub
    It doesnt work
     
  4. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    Please handle event in code module atleast for test
     
  5. narek adonts

    narek adonts Well-Known Member Licensed User

    I dont understand how can handle it in module as i am creating several times the class that i am creating and I need a timer for each of them.

    Narek
     
  6. stevel05

    stevel05 Expert Licensed User

    This works with a timer in a class, check your code against this one:
     

    Attached Files:

  7. narek adonts

    narek adonts Well-Known Member Licensed User

    I found the issue and I dont know how to fix it

    When declaring the class inside Process_Globals the timer works fine but when declaring inside any other Sub it doesnt work.

    Please advise
     
  8. stevel05

    stevel05 Expert Licensed User

    If you declare a reference to the class as a local variable, then it is likely that the class will be destroyed once the sub it's declared in is completed. You will need to hold a reference in a Global variable or a collection that is a Global variable (Array,List or Map) for the class instance to persist.
     
  9. narek adonts

    narek adonts Well-Known Member Licensed User

    Solved. Thank you )
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    This is not correct. You can handle events in classes.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice