B4J Question [RESOLVED] Trapping Form Events other then MainForm

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hi All

I have a server app. It , so far, has 3 forms, each form I have associated with it's own code module.

main -> MainForm as from (frmMain.fxml)
mod_app_connections -> frmConnections as form (frmConnections.fxml)
mod_app_settings -> frmSettings as form (frmSettings.fxml)

In the mod_app_connections code module I am trying to trap the frmConnections_Closed and/or frmConnections_CloseRequest event but they do not seem to get fired when I click the 'x' button on the form.

Is there a specific formal way of naming the form object in a code module ?

Many Thanks

John.
 

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hi Erel

Thanks for the reply. When I say server app, it is a UI app that support multiple socket connections from B4A clients, a socket connection to our main back office suite, and a connection to an SQL server. I have a form that displays the connections from the B4A clients. I have a code module designated to that form;
B4X:
'Static code module
Sub Process_Globals

   Private fx As JFX
   Private frmConnections As Form
   
   Private mnuConnViewFileClose As MenuItem
   Private mnuConnViewEditRefresh As MenuItem
   Private tvConnView As TableView
   Private clsView As class_view_connnections
   Private frmConnectionsState As Boolean
   
   
   
   
End Sub

Public Sub ui_load_connections
   
   ' // already visible, so exit   
   If frmConnectionsState Then
     Return
   End If

   ' // settings
   
   frmConnections.Initialize("",-1,-1)
   frmConnections.RootPane.LoadLayout("frmConnections")
   frmConnections.Icon = fx.LoadImage(File.DirAssets,"user_connections_rt.png")
   frmConnections.Title  = "User Connections"
   frmConnections.SetOwner(frmConnections)
   
   
   frmConnections.Show
   frmConnectionsState = True
   ' // draw the header   
   draw_connections_header
   ' // start a new thread to show the user connections
   clsView.Initialize(tvConnView)
   

End Sub

Sub close_view_connections
   
   
   
   ' // turn off
   clsView.terminate
   ' // close form
   frmConnections.Close
   ' // falg as not visible
   frmConnectionsState = False


   Log("frmConnections_Closed " & frmConnectionsState)
   
End Sub
Sub frmConnections_Closed()
   
   Log("frmConnections_Closed")
   close_view_connections
   
End Sub
Sub mnuConnViewEditRefresh_Action
   
   clsView.draw_connections
   
End Sub
Sub mnuConnViewFileClose_Action
   
   close_view_connections
   
End Sub

Sub tvConnView_Resize (Width As Double, Height As Double)
   
   draw_connections_header
   
End Sub
Sub draw_connections_header
   
   Dim cw As Double, x As Int
   
   tvConnView.SetColumns(Array As String("Connection", "IP","User","Last Packet","Packet Count","Up Time"))
   cw = tvConnView.Width/6
   
   For x = 0 To 5
     tvConnView.SetColumnWidth(x, cw)
   Next

End Sub

The function ui_load_connections is called from a button click from the Main code module. I have a class manages the updating of the table;

B4X:
'Class module
Sub Class_Globals
   
   Private fx As JFX
   Private mTV As TableView
   Private tmrRefresh As Timer
   
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(pTV As TableView)

   mTV = pTV
   tmrRefresh.Initialize("tmrRefresh",Main.appSet.svr.view_refresh * 1000)
   tmrRefresh.Enabled = True

End Sub

Sub draw_connections

   Dim x As Long
   Dim ExistingClient As mSocketConnection
   
   tmrRefresh.Enabled = False
   mTV.Items.Clear
   For x = 0 To Main.connections.Size - 1
     ExistingClient = Main.connections.get(x)
     If ExistingClient.sck.InUse Then
       
       Dim row(6) As Object
       row(0) = ExistingClient.index
       row(1) = ExistingClient.sck.sckClient.RemoteAddress
       row(2) = ExistingClient.profile.account_name
       row(3) = ExistingClient.RT.lastPacket
       row(4) = ExistingClient.RT.packetCount
       row(5) = ExistingClient.RT.upTimeDisplay

       mTV.Items.Add(row)  
     
     End If
   Next
   ' // we do this so we can dynamically handle realtime adjustments
   tmrRefresh.Interval = Main.appSet.svr.view_refresh * 1000
   tmrRefresh.Enabled = True


End Sub
Sub tmrRefresh_tick()
   
   
   draw_connections
   
   
End Sub

Sub terminate

   tmrRefresh.Enabled = False

End Sub

When the 'x' button on the top right of the form is clicked I dont get the frmConnections_Closed fired.

Any thoughts ?

regards

John.
Below is a snapshot of the IDE
upload_2014-9-17_15-47-24.png
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
frmConnections.Initialize("",-1,-1)
You are setting the event name parameter to "". This is a mistake.

I highly recommend you to use a real server app for a server solution. It will be simpler to implement and much more reliable. You can create another desktop app that connects to the server and does whatever you like.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
BTW, the main app use's a server socket, and each new connection is assigned to a socket class, it works very well. :).

We plan to convert all our legacy Vb6 apps to b4J.
 
Upvote 0
Top