iOS Code Snippet CallSub with ANY number of parameters

Discussion in 'iOS Code Snippets' started by narek adonts, Mar 9, 2019.

  1. narek adonts

    narek adonts Well-Known Member Licensed User

    Code:
    Sub CallSubX (Component As Object,SubName As String,Params() As Object)
        
    Dim no As NativeObject=Component
        
    Dim name As String=SubName
        
    Dim ll As List
        ll.Initialize2(Params)
        
    For i =0 To Params.Length-1
            name=name & 
    ":"
        
    Next
        no.GetField(
    "bi").RunMethod("raiseUIEvent:event:params:",Array(Null,name,ll))

       
    End Sub

    Example usage

    Code:
    CallSubX (Me,"event_event",Array(1,"abc",3,"def",5)

    Sub event_event(a as int, b as string, c as int, d as string, e as int)

    Log(b)

    End Sub
     
    Marc Van Cauwenberghe likes this.
  2. Erel

    Erel Administrator Staff Member Licensed User

    I don't recommend using this code. CallSub is treated in a special way by the compiler.

    If you need to pass multiple parameters to a sub that called with CallSub then change its signature to:
    Code:
    Sub MySub (Params() As Object)
    And call it with:
    Code:
    CallSub(Me, "MySub"Array(1234))
    Or pass a custom type or a Map created with CreateMap.
     
  3. narek adonts

    narek adonts Well-Known Member Licensed User

    I made this to raiseEvents from custom libraries
     
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