B4J Question _ClosedRequest wont fire on renamed windows

techknight

Well-Known Member
Licensed User
Longtime User
If I rename the MainForm to something else like OutputWindow, and I rename the Event to Match, it wont fire.

However if I rename the Event back to Mainform, but I dont touch the form name and leave it as OutputWindow, it will still fire as MainForm.

So the naming of the window isnt attaching to the Eventname for some reason. I brought it up in a different thread when I was searching, but I felt it better to start a new one.

Bug?
 

stevel05

Expert
Licensed User
Longtime User
The eventname is held internally in the object when it is initialized. It is not possible to change it after it is initialized. As the Main form is passed to the AppStart sub it must be created and initialized before the sub is called.

Why do you need to change it?
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
This is not a bug. The variable name is never important. For further discussion please start a new thread in the questions forum.

Its important to me otherwise I get confused. its like handwriting, everyone has their own way of doing things I guess.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Moved to the questions forum.

The variable name is never used at runtime.
B4X:
Dim frm1 As Form = MainForm
Dim frm2 As Form = MainForm
Dim ArrayOfForms() As Form = Array As Form(MainForm)
What is the name of this form? There is no such thing.

You can request to add an option to change the Form's event name parameter. It is unlikely to be added as the listeners are already set when your code starts.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
Now I am really confused???

frm1 and frm2 are variables? no? it just looks like your assigning it the same thing?
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
If I rename the MainForm to something else like OutputWindow, and I rename the Event to Match, it wont fire.
What does this mean? Usually, the event name does not need to change. Do have a code sample?
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    OutputWindow = Form1
    OutputWindow.SetFormStyle("UNDECORATED")
    OutputWindow.AlwaysOnTop = False
    OutputWindow.RootPane.LoadLayout("Main") 'Load the layout file.
    OutputWindow.WindowTop = 0
    OutputWindow.WindowLeft = fx.PrimaryScreen.MaxX 'Position the output window on the second monitor.
 
    'DakRTD.Initialize("COM1", "00000000", "004210", 622)
    CallTimeout = False
 
    Sleep(50)

    StatPanel.Initialize
 
    If UDPSocket1.IsInitialized = False Then UDPSocket1.Initialize("UDP", 1067, 8192) 'Use UDP sockets.
 
    OutputWindow.Show
 
End Sub

Sub OutputWindow_CloseRequest (EventData As Event)  <--Doesnt Work
    Log("We are closing the program")
    ExitApplication
End Sub

Right now I am only using 1 window. OutputWindow.

But I am getting ready to add a couple more to this code.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
If you want your mainform to have a new name, just remove all references to mainform and initialize the form yourself

B4X:
#Region Project Attributes
#End Region
Sub Process_Globals
 Private fx As JFX
End Sub
Sub AppStart (Form1 As Form, Args() As String)
 Dim myForm As Form
 myForm.Initialize("myForm",600,400)
 myForm.show
 myForm.Title = "hello"
End Sub
Sub myForm_CloseRequest (EventData As Event)
 Log("myForm closing")
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

better still put the
B4X:
Dim myForm As Form
in Process_Globals
 
Last edited:
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
maybe so
B4X:
Sub AppStart (Form1 As Form, Args() As String)
 Form1.Close
    OutputWindow.Initialize("OutputWindow",800,600)
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
Thats exactly what I needed right there. That makes sense to me.

Thanks!

Edit: Worked a charm!

The Abstraction of the form object being defined in the background is what confused the heck out of me.
 
Upvote 0
Top