B4J Question Forms

moore_it

Well-Known Member
Licensed User
Longtime User
Hi all,

i've a program that close the mainform and open a new form.
When i close the new form i need to check the closerequest event but in the new form not run.
Why ?
Where i do wrong ?

Thanks in advice
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Works fine here:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Dim frm2 As Form
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
   frm2.Initialize("frm2", 300, 300)
   frm2.Show
End Sub

Sub frm2_CloseRequest (EventData As Event)
   Log("request")
   EventData.Consume
End Sub
 
Upvote 0

moore_it

Well-Known Member
Licensed User
Longtime User
thanks for reply but i close the mainform and frm2_closerequest not run in this case.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This also works fine:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Dim frm2 As Form
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
   frm2.Initialize("frm2", 300, 300)
   frm2.Show
   Sleep(100)
   MainForm.Close
End Sub

Sub frm2_CloseRequest (EventData As Event)
   Log("request")
   EventData.Consume
End Sub

Help us help you. Take this code and modify it as needed to reproduce the problem.
 
Upvote 0

moore_it

Well-Known Member
Licensed User
Longtime User
I think when i initialize a new class and open a new form in it closing the mainform the event closerequest of the new form not run ...
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
Main
B4X:
#Region Project Attributes
    #MainFormWidth: 1024
    #MainFormHeight: 1024
#End Region

Sub Process_Globals
    Private MainForm As Form
    
    Private Class As Class1
    
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    Form1.Close
    
    Class.Initialize
        
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Class1
B4X:
Sub Class_Globals
    Private fx As JFX
    Dim frm As Form
End Sub

'Initialisiert das Objekt. Falls nötig kannst du Parameter zu dieser Methode hinzufügen.
Public Sub Initialize

    frm.Initialize("frm", 300, 300)
    frm.Show

End Sub

Sub frm_CloseRequest (EventData As Event)
    
    Log("frm_CloseRequest")
    
    EventData.Consume
    
    frm.Close
    
End Sub
 
Upvote 0
Top