B4J Question How do I iterate through/reference my open windows (Forms)?

MrKim

Well-Known Member
Licensed User
Users will have multiple windows open. Note I am opening multiple copies of the same Form. I need to check if a particular one is open. If not Open it. If it is, bring it to the front.

Thanks for your help.
 

Erel

Administrator
Staff member
Licensed User
Best way is to maintain a Set with the active forms:
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Public ActiveFormsMap As B4XSet
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    ActiveFormsMap = B4XCollections.CreateSet
    MainForm = Form1
    MainForm.RootPane.LoadLayout("1")
    ShowForm(MainForm)
End Sub

Sub MainForm_Closed
    FormClosed(MainForm)
End Sub

Public Sub ShowForm(frm As Form)
    ActiveFormsMap.Add(frm)
    frm.Show
End Sub

Public Sub FormClosed(frm As Form)
    ActiveFormsMap.Remove(frm)
End Sub
Call ShowForm whenever you want to show a form and call FormClosed from the Closed event of all forms.
 
Top