B4J Question #include - is it possible

Patrick Clark

Active Member
Licensed User
This is only really a quality of life issue but is it possible to include a separate file with Type, Const and Global Public definitions in so it can be shared with all Modules?

This way I can manage the shared stuff in one place, rather than having to update multiple code when I make a change.

I have tried creating an additional Code Module and this works for Type definitions but not for Const and Global Public variables

My include.bas looks like this:
B4X:
Sub Process_Globals
    Public const NO_REQUEST_MSG_SET As Int = -1        ' an attempt to send a message has been made but no Message has been set
    
    Public Sucessful As Boolean                        ' the last operation was successful

    Type DBResult ( _
        Columns As Map, _
        Rows As List, _
        Cursor As Int, _
        NoRows As Int)
End Sub
 

OliverA

Expert
Licensed User
Longtime User
Just a heads up: type variables (such as DBResult) that are used in serialized data that is transferred must be declared in the main module.

Update: in process_globals of main module
 
Upvote 0

Patrick Clark

Active Member
Licensed User
Just a heads up: type variables (such as DBResult) that are used in serialized data that is transferred must be declared in the main module.

Update: in process_globals of main module
Yes I read that but it works perfectly if declared in my include module.

(it may not work in jRDC2 but I'm not using that. I've just used some of the code from it to convert a SQL ResultSet to DBResult)
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
It works on both sending and receiving? If so, do both sender and receiver have the same code module that holds the DBResult type?
 
Upvote 0

Patrick Clark

Active Member
Licensed User
Yes it works send and receive

The include.bas is included in both the sender and receiver. (sender is a B4A and receiver is B4J)

The data is sent using MQTT but I have also done it with AsyncStreams

I do initialize the DBResult data in sender and receiver so (but in a class, not in Main)

B4X:
Public data as DBResult

is NOT declared in the include.bas.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…