Android Question wait for Error

hello
i use wait for in other module

B4X:
public Sub sendToUrl(   url As String ) As ResumableSub
    'Log(Sender.As(B4XPagesManager.GetPageInfoFromRoot.B4XPage.))'
    LogColor(DateTime.Now,Colors.Magenta)
   
    Dim j1 As HttpJob
    j1.Initialize("", Sender)
    j1.Download(url)'"https://www.google.com")
    Wait For (j1)     JobDone(j  As HttpJob)
    If j .Success Then
        Dim str1 As String =j.GetString
        LogColor(str1,Colors.RGB(45,45,45))
 
    Else
        LogColor("Error..",Colors.Red)
    End If
    j.Release
   
    LogColor(DateTime.Now,Colors.Blue)
    Return False'
End Sub


if i use this code in root of each page, it work true


but if i copy this code in "Code Module" class it told cannot use wait in static function

"Error description: Static code modules cannot handle events."

plz help

thanks
 
1741149248967.png


hello

inside class have this error and cannot use this module.

i use this code in main

Dim ClassObject As httpclass2
ClassObject.Initialize


1741149610213.png


this is in main
 
Last edited:
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Not properly awake yet, but shouldnt it be Class_Globals and not Process_Globals in a class?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
inside class have this error and cannot use this module
It is NOT A CLASS. See Line 1 of httpclass2. It is a codemodule.
Static modules can not handle events.

The solution ist to switch to a Class, a Service or an Activity.
Best is to use B4XPages.
Remember that B4XPage pages are classes.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
inside class have this error
What we are trying to say is that you're not using a class, but a code module.

Add a "Standar class" and copy the code from your "Code Module" called http2class to the new created (and real) class

1741160557558.png
 
Upvote 0
What is the error?

What we are trying to say is that you're not using a class, but a code module.

Add a "Standar class" and copy the code from your "Code Module" called http2class to the new created (and real) class

View attachment 162279
ok
it have not Error.
but on run project wait on this line
"Wait For (j1) JobDone(j1 As HttpJob)"
in mainpage this line work true but it this class only wait


in main i use this:


Dim ClassObject As httpclass3
ClassObject.Initialize
ClassObject.sendToUrl( "http://1xxxx3:8891/token?User=1&Pass=1")

1741163984681.png
 
Upvote 0
It is NOT A CLASS. See Line 1 of httpclass2. It is a codemodule.
Static modules can not handle events.

The solution ist to switch to a Class, a Service or an Activity.
Best is to use B4XPages.
Remember that B4XPage pages are classes.
when we can use "code module" and when we can use "standard class"? i need more info. have you manual or datasheet in this way?
thanks
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

josejad

Expert
Licensed User
Longtime User
read docs

but cannot see any about different between code module and standard module.


I will start by explaining the differences between classes, code modules and types.

Similar to types, classes are templates. From this template, you can instantiate any number of
objects.
The type fields are similar to the classes’ global variables. However, unlike types which only define
the data structure, classes also define the behaviour. The behaviour is defined in the classes’ subs.

Unlike classes which are a template for objects, code modules are collections of subs. Another
important difference between code modules and classes is that
code modules always run in the
context of the calling sub. The code module does not hold a reference to any context. For that
reason, it is impossible to handle events or use CallSub with code modules.
Classes store a reference to the context of the module that called the Initialize sub. This means that
classes objects share the same life cycle as the module that initialized them.
 
Upvote 0
Top