B4J Question One Form : module or class

besoft

Active Member
Licensed User
Longtime User
Hi,

I have a form with several buttons and other controls. In the background is a lot of code, I would like to individual parts of an application made in another module.

Is it better to use a module or class. How to call from the second module, for example a textfield from the main module?

THX
 

Cableguy

Expert
Licensed User
Longtime User
Classes and Modules are at their base similar but with different in their objectives.
A code Module should be used to split large code projects into manageable Modules BUT should NOT directly call or interact with UI objects.
For that particular purpose, you should use a Class.
 
Upvote 0

besoft

Active Member
Licensed User
Longtime User
Thanks for the reply.

I tried to put a timer in the class.What I miss,it does not work?
B4X:
Sub Class_Globals
    Private fx As JFX
    Public tmr As Timer
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
tmr.Initialize("tmr",1000)
tmr.Enabled = True
End Sub

Sub tmr_Tick
Main.TextArea1.Text = "ok"
End Sub
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

pls find attached a small tested example.
 

Attachments

  • TimerInClass.zip
    2.3 KB · Views: 181
Upvote 0

besoft

Active Member
Licensed User
Longtime User
It is also possible to use the buttons in the class?
B4X:
Sub Class_Globals
    Private fx As JFX
    Public tmr As Timer
    Public Button7 As Button
   
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
tmr.Initialize("tmr",1000)
tmr.Enabled = True
'Button7.Initialize("Button7")
End Sub

Sub tmr_Tick
Main.TextArea1.Text = Main.TextArea1.Text & "ok" & CRLF
'Log("OK")
End Sub

Sub Button7_Action
    Log("ok")
End Sub
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
You can use what eve you like in a class, but you should pass the owner to the initialize sub

have a look at the custom Views examples, they ARE classes that add functionality to a form in the form of a complex view
 
Upvote 0
Top