Android Question Event & Class

Discussion in 'Android Questions' started by jinyistudio, Mar 20, 2015.

  1. jinyistudio

    jinyistudio Active Member Licensed User

    Hi
    I declare a new class. i have some event in ths class.
    Like pgTimer1.Initialize("timer1",25),It hasn't need Targetobj As object.
    Could i erase TargetObj in my Initialize function and how to implement it like timer1.Initialize ?

    Code:
    'Events declaration
    #Region Events
    #Event: OnRequest(EvtNum as int,buff() as byte,len as int)
    #Event: OnRespone(EvtNum as int,buff() as byte,len as int)
    #Event: OnTimeout(EvtNum as int)
    #End Region

    'Class module
    Sub Class_Globals
        
    Private pgDevName As String = ""
        
    Private pgEvtName As String = ""
        
    Private pgBaud As Int
        
    Private pgProtocol As Int=0 '0=asc 1=rtu
        Private pgTimer1 As Timer
        
    Private pgTarget As Object
    End Sub

    'Initializes the object. You can add parameters to this method if needed.
    Public Sub Initialize(TargetObj As Object,EventName As String)
        pgTarget = TargetObj
        pgEvtName = EventName
        pgTimer1.Initialize(
    "timer1",25)
    End Sub

    Public Sub Open(devname As String,baudrate As Int)
        pgDevName = devname
        pgBaud = baudrate
        
    CallSub3(modserv,"OpenSerial",pgDevName,pgBaud) ' /dev/ttymxc2
        StartService(modserv)
        pgTimer1.Enabled = 
    True
    End Sub

    Private Sub timer1_tick
        
    If Not(modserv.Connected) Then
            
    Return
        
    End If
       
        
    If SubExists(pgTarget,pgEvtName & "_ObRequest"Then
            CallSubDelayed(pgTarget,pgEvtName & 
    "_ObRequest")
        
    End If
    End Sub
     
  2. DonManfred

    DonManfred Expert Licensed User

    no. You need the target when you want to fire any events.
    just extend your initialize method to get more parameters to the class
    Code:
    Public Sub Initialize(TargetObj As Object,EventName As String, ms As Int)
        pgTarget = TargetObj
        pgEvtName = EventName
        pgTimer1.Initialize(
    "timer1",ms)
    End Sub
     
    jinyistudio likes this.
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