Call script from custom class - v8.0.1

Hello Experts

I have a custom class, and in the new operator I am calling an existing script to do some calculations. However, when I compile I get the following error:

Reference to a non-shared member requires an object reference

I guess this make sense since all the customer scripts reside in a separate class.

Question is: How can I access the functions (i.e. scripts) from within my custom class?

Thanks

Kin

Parents Reply Children
  • Right, so the issue is I somehow need to get Session passed into the function (as you mentioned previously Markus, I missed that part). I'll work on this and if I find a solution I'll update this - I'm guessing I need to pass the session as a parameter from the object of the class somehow. Keeping this thread open in the meantime

  • Got it, pasting the source code here - the key is to have a session member variable

    Class Test
    
    	Public _s As VI.DB.Entities.ISession
    	Dim _prop As String
    	
    	Public Property Prop() As String
    		Get
    			Return Me._prop
    		
    		End Get
    		
    		Set(ByVal t As String)
    			Dim runner = New VI.DB.Scripting.ScriptRunner(Me._s.Scripts()(VI.DB.Scripting.ScriptContext.Scripts), Me._s)
    			Dim result = runner.Eval("CCC_MyScript", {"John", "@company.com"})
    			Me._prop = CStr(result)
    		End Set
    		
    	End Property
    	
    End Class
    
    Public Function  CCC_Myfunc() As String
    
    		Dim p As New Test With {._s = Session, .Prop = "ha"}
    		Return p.Prop
    	
    End Function