CallSub result should be Object?

galimpic

Member
Licensed User
Longtime User
Is there a reason that CallSub result is defined as String, not Object? When I want to return an object, it cannot be cast:

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:

EduardoElias

Well-Known Member
Licensed User
Longtime User
I agree. It will be changed in the future.

Erel,

How long to that happens?

More I am writing libraries and new modules, more I am finding need the support for class inheritance, and this callsub method returning object helps a little.

Eduardo

EDIT: eventually instead changing Callsub* create a new version of it returning the object for legacy reasons not breaking those waiting for string (not sure that makes sense, just trying to get problems out of the way to make this a reality soon). I am bringing all the Delphi Database/DataSet/Fields structure to B4A in order to have real support for database connection to fields etc, like any RAD IDE. I hope it works. It is a lot of code, but looks promissing.
 
Last edited:

melamoud

Active Member
Licensed User
Longtime User
+1 here this is really urgent for me, when can we see it happen ?

thanks
 
Top