B4J Question How to create own Library ?

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi

I want to create a new library with B4J. But I don't know how to implement following function code of Initialize,Event. Do you have sample code about creating B4J Libray ?
 

Cableguy

Expert
Licensed User
Longtime User
It all dépends on which type (complexity) of lib you want...
B4x offers the possibility of compiling classes into libs... So you can take your "I use every day" code and turn it into a lib or if you need to wrap more complex and not yet available functionality, you may need external tools like eclipse.check the new 2 controls added to the extraviews example... Source code is available too.
 
Upvote 0

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi
I create a standard class as following:
Please tell me how to call the Event when i add a parameter in the Sub of Initialize(vEventName As String)
Or I just can use Initialize (vCallback As Object, vEventName As String) ??

B4X:
#DesignerProperty: key: Protocol, displayname: ASC,RTU, fieldtype: int, defaultvalue:

Sub Class_Globals
    Private EventName As String 'ignore
    Private pgProtocol As Int
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(vEventName As String)
    EventName = vEventName
End Sub

Public Sub getProtocol As Int
    Return pgProtocol
End Sub

Public Sub setProtocol (v As Int)
    pgProtocol = v
End Sub
 
Last edited:
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
What is the class meant to do?
It looks like a custom control with the #DesignerProperty line

If you just want a 'normal' library in your project click
Project>Add New Module>Class Module>Standard Class

Add your code to it

In the 'main' you can test your library by adding in globals
B4X:
Dim myLibrary As MyNewLibrary
Then you can call initialize etc

When you are happy it all works fine then click
Project>Compile To Library
and the IDE will produce the jar and xml for the library.
 
Last edited:
Upvote 0

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi

Yes,I Know. My Question is, I will have some Event in this class.
when i use this class in main module, I will give it a Eventname as following.
But I don't know how to trigger(call back) Event from this class.

private a as modbus
a.Initialize("modbus1")
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…