Hi, I am experimenting with B4J and specific with Jrdc2.
I followed the great example and it works nice, but I can only access the database in main module.
Because I will use it in a multi form application, where each form has it's own code-module I was looking for a way to move the JRDC specific code to an other place that can be accessed from anywhere in the application.
I moved the next code from main to a new code module named modJrdc2
In each form where I want to execute select or inserts I placed simular code as below.
Note that functions are pointed to modJrdc2.
There is no error at all. But the spinner didin't fill any data.
Before with all the code in main it works very well.
I followed the great example and it works nice, but I can only access the database in main module.
Because I will use it in a multi form application, where each form has it's own code-module I was looking for a way to move the JRDC specific code to an other place that can be accessed from anywhere in the application.
I moved the next code from main to a new code module named modJrdc2
B4X:
'Static code module
Sub Process_Globals
Private fx As JFX
Type DBResult (Tag As Object, Columns As Map, Rows As List)
Type DBCommand (Name As String, Parameters() As Object)
Private const rdcLink As String = "http://192.168.2.34:17178/rdc"
End Sub
Public Sub CreateRequest As DBRequestManager
Dim req As DBRequestManager
req.Initialize(Me, rdcLink)
Return req
End Sub
Public Sub CreateCommand(Name As String, Parameters() As Object) As DBCommand
Dim cmd As DBCommand
cmd.Initialize
cmd.Name = Name
If Parameters <> Null Then cmd.Parameters = Parameters
Return cmd
End Sub
In each form where I want to execute select or inserts I placed simular code as below.
Note that functions are pointed to modJrdc2.
B4X:
Sub Load_UserNames
Dim req As DBRequestManager = modJrdc2.CreateRequest
Dim cmd As DBCommand = modJrdc2.CreateCommand("select_usernames", Null)
Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
If j.Success Then
req.HandleJobAsync(j, "req")
Wait For (req) req_Result(res As DBResult)
'work with result
req.PrintTable(res)
cbGebruikers.Items.Clear
For Each row() As Object In res.Rows
cbGebruikers.Items.add(row(0))
Next
Else
Log("Error: " & j.ErrorMessage)
End If
j.Release
End Sub
There is no error at all. But the spinner didin't fill any data.
Before with all the code in main it works very well.