Hang on Release ChildWindow

Moderator: Rathinagiri

Post Reply
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Hang on Release ChildWindow

Post by hmgchang »

Dear Friends,

Try Release a Child Window :

Code: Select all

/*
* HMG This Demo
* (c) 2003 Roberto Lopez
*/

#include "hmg.ch"

Function Main

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 400 ;
		HEIGHT 200 ;
		TITLE 'This Demo' ;
		MAIN ;
		ON INIT ThisWindow.Title := 'New Title'

		@ 10,10 BUTTON Button_1 ;
			CAPTION 'Hi!!!' ;
			ACTION ThisTest() ;
			TOOLTIP 'Test Tip'

		@ 40,10 BUTTON Button_2 ;
			CAPTION 'Release' ;
			ACTION ThisWindow.Release 
      
    @ 70,10 BUTTON Button_3 ;
			CAPTION 'New Window' ;
			ACTION NewWindow() ;
			TOOLTIP 'Create New Window'  
      
    @ 100,10 BUTTON Button_4 ;
			CAPTION 'Release New Window' ;
      WIDTH 200 ;
			ACTION ReleaseNewWindow()

	END WINDOW

	CENTER WINDOW Form_1

	ACTIVATE WINDOW Form_1

Return

FUNCTION ReleaseNewWindow()
  IF IsWindowDefined( "NewWindow")
    msgDebug( "before")
    DoMethod( "NewWindow", "Release")
    msgDebug( "after")
  ELSE
    MsgInfo( "Click New Window!")
  ENDIF
  RETURN NIL

FUNCTION NewWindow()
  DEFINE WINDOW NewWindow ;
		AT 20,20 ;
		WIDTH 400 ;
		HEIGHT 300 ;
    CHILD ;
		TITLE 'New Window' 
    
  END WINDOW  
  ACTIVATE WINDOW NewWindow  
  RETURN NIL
  

Procedure ThisTest()

	This.Caption  := 'New Caption'

	ThisWindow.Row := 10
	ThisWindow.Col := 10
	ThisWindow.Width := 200
	ThisWindow.Height := 100

Return

Pls advise what is wrong...
TIA
best rgds,
Chang
Just Hmg It !
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

Re: Hang on Release ChildWindow

Post by KDJ »

Chang

Try to use DoEvents() function after release "NewWindow":

Code: Select all

FUNCTION ReleaseNewWindow()
  IF IsWindowDefined(NewWindow)
    msgDebug( "before")
    DoMethod( "NewWindow", "Release")
    DoEvents()
    msgDebug( "after")
  ELSE
    MsgInfo( "Click New Window!")
  ENDIF
  RETURN NIL
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: Hang on Release ChildWindow

Post by hmgchang »

Thanks KDJ,
it works...
can i have some explanation on the doEvents() and when to use it ?

TIA

best rgds,
Chang
Just Hmg It !
User avatar
vagblad
Posts: 160
Joined: Tue Jun 18, 2013 12:18 pm
DBs Used: MySQL,DBF
Location: Thessaloniki, Greece

Re: Hang on Release ChildWindow

Post by vagblad »

Hi Chang,

The DoEvents() is a way to "force" the program to execute any event that has been triggered even during big loops. For example you can use it during a WHILE or a FOR loop.
For i := 1 to LASTREC()
DoEvents()
"stuff to do inside the loop"
Next i

The above will make sure that everytime your loop runs the program will also execute any triggered events as well(timers,focus etc.) instead of waiting for the loop to finish to proceed.
I personally think of it as a "pseudo-multi threading" - i may be wrong - . It is very useful in such situations as the above.
Now considering your own example and the hanging, unfortunately we had the same problems whenever we used child windows and had to pop a modal window after a release of a child window. It seems that when the msgdebug window pops(which is a modal window) it doesn't get focus or it's just not visible at all. So the modal window opens but you cannot see it - thus you cannot close it to continue the execution of your app - thus the app looks like it "hangs".
Why the DoEvents() helps to overcome that i dont know.

Hope it helped a bit :)
Vagelis Prodromidis
Email: vagblad@gmail.com, Skype: vagblad
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: Hang on Release ChildWindow

Post by hmgchang »

Thanks Mr. VP...

Code: Select all

 func1()
Doevents()
Func2()
The doEvents() effected to func1 or func2 ?
TIA

Best rgds
Chang
Just Hmg It !
User avatar
vagblad
Posts: 160
Joined: Tue Jun 18, 2013 12:18 pm
DBs Used: MySQL,DBF
Location: Thessaloniki, Greece

Re: Hang on Release ChildWindow

Post by vagblad »

hmgchang wrote: Fri Jun 01, 2018 12:43 pm Thanks Mr. VP...

Code: Select all

 func1()
Doevents()
Func2()
The doEvents() effected to func1 or func2 ?
TIA

Best rgds
Chang
It affects both of them and none of them at the same time if it makes sense?
Your func1() will run and when it is done the doevents will execute any event that was triggered, BEFORE executing the func2().
If you didn't have the DoEvents() there then your app would have to execute func1() first then func2() and execute any events triggered meanwhile after both of these functions were finished.

Keep in mind that always unless you multi-thread your functions the app executes them 1 by 1 like in a FIFO stack.
The events which are triggered are executed while the app is in "waiting" mode, meaning that no Function is being executed at the time.

For example:

Code: Select all

Function Run2Functions()
func1()
  --- User clicks on a Grid which has an ONGOTFOCUS event msginfo("Grid clicked") ---
func2()
The "Grid clicked" message will appear after func2() has finished executing.

Code: Select all

Function Run2Functions()
func1()
DoEvents()
  --- User clicks on a Grid which has an ONGOTFOCUS event msginfo("Grid clicked") ---
func2()
The "Grid clicked" message will appear after func1() has finished executing and then the app will continue to execute the func2().

I know the examples are a bit simplistic but i hope they will help. :)
Vagelis Prodromidis
Email: vagblad@gmail.com, Skype: vagblad
Post Reply