Wish RunMethod for every nodes

jmon

Well-Known Member
Licensed User
Longtime User
Hi,

I think it would be very convenient to have a .RunMethod method for every node. So we would need to create new variables as JavaObject when running external methods.
Current:
B4X:
Dim l As Label
l.Initialize("")
l.Text = "Blah"
Dim lJo As JavaObject = l
lJo.RunMethod("setRotate", Array(90.0))

Suggested:
B4X:
Dim l As Label
l.Initialize("")
l.Text = "Blah"
l.RunMethod("setRotate", Array(90.0))

Or:
B4X:
Dim l As Label
l.Initialize("")
l.Text = "Blah"
l.asJo.RunMethod("setRotate", Array(90.0))

I currently use the asJo snippet from @Daestrum (https://www.b4x.com/android/forum/threads/javaobjects-the-easy-way.45121/), which is very good, but I found that this new proposition would be a great addition.

Thank you
Jmon.
 

jmon

Well-Known Member
Licensed User
Longtime User
Thanks

I was thinking about a general way of calling any Javafx method, like setPrefWidth, setMinWidth, setGraphic etc... that doesn't exist in B4J
At the moment I use the asJo method by daestrum, which I find convenient enough. This idea I propose is just to make the code simpler and cleaner, nothing more :)
 

Daestrum

Expert
Licensed User
Longtime User
If, in Erels example, you change n As Node to JavaObject, you don't need to create jo and can use n.RunMethod("...",...)
 

tango

Member
Licensed User
Longtime User
hi erel
RunMethod("setRotate", Array(Degrees))
what are the other parametres. eg. "setrotate","gettext", etc.
 

Daestrum

Expert
Licensed User
Longtime User
An all purpose sub - not quite what you wanted but flexible to allow for any method call
B4X:
...   
    Dim l As Label
    l.Initialize("")
    l.Text = "Hello"
    MainForm.RootPane.AddNode(l,20,20,-1,-1)
    RunMethod(l,"setRotate",Array(45.0))
End Sub
Sub RunMethod(n As JavaObject,method As String,args() As Object)
    n.RunMethod(method,args)
End Sub
 
  • Like
Reactions: eps

eps

Expert
Licensed User
Longtime User
An all purpose sub - not quite what you wanted but flexible to allow for any method call
B4X:
...  
    Dim l As Label
    l.Initialize("")
    l.Text = "Hello"
    MainForm.RootPane.AddNode(l,20,20,-1,-1)
    RunMethod(l,"setRotate",Array(45.0))
End Sub
Sub RunMethod(n As JavaObject,method As String,args() As Object)
    n.RunMethod(method,args)
End Sub

Thanks for this - I've just re-purposed this and also added a return value as well :)

B4X:
Sub RunMethod(n As JavaObject,method As String,args() As Object) As Object

    Return n.RunMethod(method,args)

End Sub

:)
 
Top