Is there a reason that CallSub result is defined as String, not Object? When I want to return an object, it cannot be cast:
I have to use the trick with array of objects parameter:
So, there is a workaround, but it is cumbersome... maybe the return type for CallSub should be more general to avoid this problem?
P.S. Hi everybody, this is my first post
B4X:
'In Main module
Type MyClass(a as int) 'can be any other class type
...
Sub MainSub as MyClass
Dim res as MyClass
res.Initialize
return res
End Sub
...
'In, say, Code module
Sub CodeSub
Dim x as MyClass
x = CallSub(Main, "MainSub") 'java "inconvertible types" error during compile
x.a = 1
End Sub
I have to use the trick with array of objects parameter:
B4X:
'In Main module
Type MyClass(a as int) 'can be any other class type
...
Sub MainSub(x() as MyClass)
Dim res as MyClass
x(0).Initialize
End Sub
...
'In, say, Code module
Sub CodeSub
Dim x(1) as MyClass
CallSub2(Main, "MainSub", x) 'this works
x(0).a = 1
End Sub
So, there is a workaround, but it is cumbersome... maybe the return type for CallSub should be more general to avoid this problem?
P.S. Hi everybody, this is my first post
Last edited: