Android Question Passing Different Object into B4X Library Function

Richard Goh

Active Member
Licensed User
Longtime User
Hi,

I would like to check whether is it possible to be done in B4A?
I would like to pass in different object into a common B4X Library function for HttpJob I created as below.
Then the result will pass to each object function to process the result. Is this approach can be achieve in B4X or is there any alternative way to achieve this?
Thanks in advance.

B4X:
Sub startJob(obj As Object)
        Dim j As HttpJob
        j.Initialize("", Me) 'name is empty as it is no longer needed
        j.Tag = obj
        j.PostString("http://x.sss.com/api/Test",body)
        j.GetRequest.SetContentType("application/json")
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            obj = j.Tag
            obj.ParseJSON(j.GetString) 'here different object function will process the result'                               
        End If    
        j.Release      
End Sub
 

agraham

Expert
Licensed User
Longtime User
obj.ParseJSON(j.GetString)
This cannot work as Type Object will not be recognised as having a ParseJSON method. You would need to assign the Object instance to a variable of the correct type to access its ParseJSON method. You can check the type of an Object instance using the IS keyword.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I would like to check whether is it possible to be done in B4A?
Everything is possible.

Then the result will pass to each object function to process the result. Is this approach can be achieve in B4X or is there any alternative way to achieve this?
You can pass the name of a sub of the specific parser, or a class instance with a specific interface. In both cases you should call them with CallSub.
 
Upvote 0
Top