At first, one can write a program that have 2 ( or more ) WND_MAIN windows, invoking ::s_qApp:exec() 2 ( or more ) times and this causes the application to close when the last WND_MAIN window is released. And its possibly that there are other consequences in invoking ::s_qApp:exec() more than one time...
See:
Code: Select all
#include "hmg.ch"
FUNCTION Main()
LOCAL oMainWindow
LOCAL oButton1
LOCAL oButton2
HbQt_ErrorSys()
WITH OBJECT oMainWindow := Window():New()
:Width := 200
:Height := 400
:Title := "Tests"
:Type := WND_MAIN
:OnInit := {|| oMainWindow:Center()}
WITH OBJECT oButton1 := Button():New()
:Row := 40
:Col := 10
:Width := 180
:Caption := 'Click to Open Child Window'
:OnClick := { || ChildWindow() }
END WITH
End // oMainWindow
oMainWindow:Activate()
RETURN
FUNCTION ChildWindow()
LOCAL oChildWindow
LOCAL oButton3
WITH OBJECT oChildWindow := Window():New()
:Width := 400
:Height := 300
:Title := "Child Window"
:Type := WND_MAIN
:OnInit := { || oChildWindow:Center() }
WITH OBJECT oButton3 := Button():New()
:Row := 40
:Col := 10
:Width := 380
:Caption := 'Click to Close Child Window'
:OnClick := { || oChildWindow:Release() }
END WITH
End // oChildWindow
oChildWindow:Activate()
RETURN NIL
Try this:
Code: Select all
#include "hmg.ch"
FUNCTION Main()
LOCAL oMainWindow
LOCAL oButton1
LOCAL oButton2
HbQt_ErrorSys()
WITH OBJECT oMainWindow := Window():New()
:Width := 200
:Height := 400
:Title := "Tests"
:Type := WND_MAIN
:OnInit := {|| oMainWindow:Center()}
WITH OBJECT oButton1 := Button():New()
:Row := 40
:Col := 10
:Width := 180
:Caption := 'Click to Open Child Window'
:OnClick := { || ChildWindow() }
END WITH
End // oMainWindow
oMainWindow:Activate()
oMainWindow := NIL
RETURN
FUNCTION ChildWindow()
LOCAL oChildWindow
LOCAL oButton3
WITH OBJECT oChildWindow := Window():New()
:Width := 400
:Height := 300
:Title := "Child Window"
:Type := WND_STANDARD
:OnInit := { || oChildWindow:Center() }
WITH OBJECT oButton3 := Button():New()
:Row := 40
:Col := 10
:Width := 380
:Caption := 'Click to Close Child Window'
:OnClick := { || oChildWindow:Release() }
END WITH
End // oChildWindow
oChildWindow:Activate()
oChildWindow := NIL
RETURN NIL
Code: Select all
oChildWindow:Activate()
Code: Select all
oChildWindow := NIL
Someone can ask "Why oChildWindow := NIL ?" and the answer is to release the memory used by controls not needed anymore.
This two problems can be fixed if only one WND_MAIN is allowed, forcing the first one to be the WND_MAIN and any subsequent ones other types, even if defined as WND_MAIN.
And generating a loop in every type, not only WND_MAIN and WND_MODAL.
I will change window.prg this way, if someone have any comment, please do.