Re Entrant Programs- How to
Moderator: Rathinagiri
Re Entrant Programs- How to
Friends of HMG
I want to know how to make my program re-entrant.
By that term I mean that if the program functions are completed but you want a message to ask "Press R re re-enter or E to Exit" How do you avoid runtime crashes when a window or control is found to be already declared due to the first pass.
I tried using a flag like STATIC lIsFirstRun:=.T. and setting it .F. at the end when the question is asked and "R" is selected. The intention would be to skip around a DECLARE of a window or control after the first pass.
That does not work if skipping the DECLARE bypasses an ACTION associated with the control.
Is there a better way such as using window release/ restore? I found no Samples of this.
Does a window release include all controls on that window?
Thanks
I want to know how to make my program re-entrant.
By that term I mean that if the program functions are completed but you want a message to ask "Press R re re-enter or E to Exit" How do you avoid runtime crashes when a window or control is found to be already declared due to the first pass.
I tried using a flag like STATIC lIsFirstRun:=.T. and setting it .F. at the end when the question is asked and "R" is selected. The intention would be to skip around a DECLARE of a window or control after the first pass.
That does not work if skipping the DECLARE bypasses an ACTION associated with the control.
Is there a better way such as using window release/ restore? I found no Samples of this.
Does a window release include all controls on that window?
Thanks
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: Re Entrant Programs- How to
You can check IsWindowDefined() function to check whether the window is already defined or not.
When you release a window, all the controls will also be released.
When you release a window, all the controls will also be released.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
- serge_girard
- Posts: 3165
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Contact:
Re: Re Entrant Programs- How to
Bluebird,
I use this:
Serge
I use this:
Code: Select all
If !IsWIndowActive (Form_1)
DEFINE WINDOW Form_1
...
END WINDOW
CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1
ELSE
Form_OZ_1.SetFocus
ENDIF
There's nothing you can do that can't be done...
Re: Re Entrant Programs- How to
Hello Bluebird,serge_girard wrote:Bluebird,
I use this:Code: Select all
If !IsWIndowActive (Form_1) DEFINE WINDOW Form_1 ... END WINDOW CENTER WINDOW Form_1 ACTIVATE WINDOW Form_1 ELSE Form_OZ_1.SetFocus ENDIF
Please try the following template application:
Code: Select all
#include "hmg.ch"
/* #define COLOR_LightGoldenrod { 238 , 221 , 130 } */
/******
*
* Template for application
*
*/
Procedure Main
SET FONT TO 'Tahoma', 10
DEFINE WINDOW MainWin ;
AT 0, 0 ;
WIDTH 600 ;
HEIGHT 400 ;
MAIN ;
TITLE 'Template Demo' ;
BACKCOLOR COLOR_LightGoldenrod ;
ICON "MAIN"
CreateMainMenu()
DEFINE STATUSBAR FONT 'Tahoma' SIZE 9
STATUSITEM 'HMG Power Ready!'
END STATUSBAR
ON KEY ALT+X ACTION { || QuickExit() }
END WINDOW
CENTER WINDOW MainWin
ACTIVATE WINDOW MainWin
Return
****** End of Main ******
/******
*
* CreateMainMenu()
*
* Cteate Main Menu
*
*/
Static Procedure CreateMainMenu
DEFINE MAIN MENU OF MainWin
POPUP '&File'
ITEM '&Child Window' ACTION Child_Click()
ITEM '&Modal Window' ACTION Modal_Click()
SEPARATOR
ITEM 'E&xit' + Chr(9) + 'Alt+X' ACTION { || QuickExit() }
END POPUP
END MENU
Return
****** End of CreateMainMenu ******
/******
*
* QuickExit()
*
* Exit from application
*
*/
Static Procedure QuickExit
QUIT
Return
***** End of QuickExit ******
/******
*
* Child_Click()
*
* Cteate Child Window
*
*/
Procedure Child_Click
IF IsWindowDefined ( ChildWin )
DoMethod ( "ChildWin", "SetFocus" )
Return
ENDIF
DEFINE WINDOW ChildWin ;
AT 0, 0 ;
WIDTH 400 ;
HEIGHT 300 ;
CHILD ;
TITLE 'Child Window'
ON KEY ESCAPE ACTION ThisWindow.Release()
END WINDOW
ChildWin.Center()
ChildWin.Activate()
Return
***** End of Child_Click ******
/******
*
* Modal_Click()
*
* Cteate Modal Window
*
*/
Procedure Modal_Click
DEFINE WINDOW ModalWin ;
AT 0, 0 ;
WIDTH 400 ;
HEIGHT 300 ;
MODAL ;
TITLE 'Modal Window'
ON KEY ESCAPE ACTION ThisWindow.Release()
END WINDOW
ModalWin.Center()
ModalWin.Activate()
Return
***** End of Modal_Click ******
Kind Regards,
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
- Roberto Lopez
- HMG Founder
- Posts: 4004
- Joined: Wed Jul 30, 2008 6:43 pm
Re: Re Entrant Programs- How to
Or simply, using NOAUTORELEASE style, then, all the windows are created once at program startup and you show or hide when required, so re-entrance is not a problem at all (you only must skip the code segment where all windows were defined, if one of them (ie: main) was already defined).bluebird wrote:Friends of HMG
I want to know how to make my program re-entrant.
<...>
There is four NOAUTORELEASE samples in \SAMPLES\BASICS\.
In fact, when I've added this feature, I've hoped that it was massively adopted, but that not happened.
I guess that the Clipper model of defining controls every time were required won, simply because all we are familiar with it, even is (by far) less efficient.
Regards/Saludos,
Roberto
(Veritas Filia Temporis)
Roberto
(Veritas Filia Temporis)
- Roberto Lopez
- HMG Founder
- Posts: 4004
- Joined: Wed Jul 30, 2008 6:43 pm
Re: Re Entrant Programs- How to
And...
I like specially the demo '4'. It is super clean, nice and simple.
This paradigm is wonderful for code maintenance.
It's not required that the windows be created from IDE. Remember that LOAD WINDOW works with code created manually too, so, could be easy to translate your current 'non-IDE' generated forms, to use this scheme.
So... for your problem:
I like this scheme so much, that this is the way that JMG works (all pages defined at startup, showing each one when required).
I like specially the demo '4'. It is super clean, nice and simple.
This paradigm is wonderful for code maintenance.
It's not required that the windows be created from IDE. Remember that LOAD WINDOW works with code created manually too, so, could be easy to translate your current 'non-IDE' generated forms, to use this scheme.
So... for your problem:
Code: Select all
/*
* HMG - Harbour Win32 GUI library Demo
*
* Copyright 2002 Roberto Lopez <mail.box.hmg@gmail.com>
* http://www.hmgforum.com//
*/
* NoAutoRelease Style Demo / ACTIVATE WINDOW ALL command
* Using ACTIVATE WINDOW ALL command, all defined windows will be activated
* simultaneously. NOAUTORELEASE and NOSHOW styles in non-main windows
* are forced.
#include "hmg.ch"
DECLARE WINDOW Std_Form
DECLARE WINDOW Child_Form
DECLARE WINDOW Topmost_Form
DECLARE WINDOW Modal_Form
Function Main
If .Not. IsWindowDefined( Main_Form )
LOAD WINDOW Main_Form
LOAD WINDOW Std_Form
LOAD WINDOW Child_Form
LOAD WINDOW Topmost_Form
LOAD WINDOW Modal_Form
ACTIVATE WINDOW ALL
EndIf
Return Nil
Regards/Saludos,
Roberto
(Veritas Filia Temporis)
Roberto
(Veritas Filia Temporis)
Re: Re Entrant Programs- How to
I tried the IsWindowActive() but please look at the code below
When the reentry occurs I get to the diagnostic msgstop() to show that I reached the end but after that the program exits.
I would have thought from the responses that I got that the "Form_2.setfocus would allow me to make a choice via button_1 or _2 set.
However the program trucks on and self-exits.
What am I doing wrong?
Thanks HMG guys
*-----------------------------------------------
FUNCTION MATRIXFUNSTART() //Called from Startup Button
*-----------------------------------------------
STATIC lIsFirstEntry:=.T.
LOCAL lUseSubs:=.t., cYesNo, cDimensions:="?",cFirst,cIsActive
cFirst:=iif(lIsFirstEntry,"First", "ReEntry")
Do while !(cDimensions $"23")
cDimensions:= alltrim(Inputbox("Enter a No of rows and columns","Form_1","?"))
if !(cDimensions $"23")
msgstop(" Can't handle that entry yet")
else
nRows:= val(cDimensions) ; nCols:= nRows
endif
Enddo
DrawMatrixBoxes()
cIsActive:=iif(IsWindowActive (Form_2),"Yep","Nope") // diagnostic
MsgStop("Is Form_2 Active ? "+cIsActive)
//lFEParameter:=lIsFirstEntry
//If lIsFirstEntry
If !IsWIndowActive (Form_2)
DEFINE WINDOW Form_2 ;
AT 290,290 ;
WIDTH 400 ;
HEIGHT 300 ;
BACKCOLOR GREEN ;
TITLE "Choose Data Source"
@ 50 ,100 BUTTON Button_1 ;
PARENT Form_2;
CAPTION "Click to Use Test Values" ;
ONCLICK {||(lUseTestMatrix:=.t.,lIsFirstEntry:=.F., BackToForm_1b())} ;
WIDTH 200 ;
FONT "Arial" SIZE 12 ;
HEIGHT 35
@ 100 ,100 BUTTON Button_2 ;
PARENT Form_2;
CAPTION "Click to enter New Values" ;
ONCLICK {||(lUseTestMatrix:=.f.,lIsFirstEntry:=.F., BackToForm_1b())} ;
FONT "Arial" SIZE 12 ;
WIDTH 200 ;
HEIGHT 35
END WINDOW
ACTIVATE WINDOW Form_2
Else
Form_2.setfocus
msgstop("At end of MatrixFunStart")
Endif //lIsFIrstEntry
RETURN
When the reentry occurs I get to the diagnostic msgstop() to show that I reached the end but after that the program exits.
I would have thought from the responses that I got that the "Form_2.setfocus would allow me to make a choice via button_1 or _2 set.
However the program trucks on and self-exits.
What am I doing wrong?
Thanks HMG guys
*-----------------------------------------------
FUNCTION MATRIXFUNSTART() //Called from Startup Button
*-----------------------------------------------
STATIC lIsFirstEntry:=.T.
LOCAL lUseSubs:=.t., cYesNo, cDimensions:="?",cFirst,cIsActive
cFirst:=iif(lIsFirstEntry,"First", "ReEntry")
Do while !(cDimensions $"23")
cDimensions:= alltrim(Inputbox("Enter a No of rows and columns","Form_1","?"))
if !(cDimensions $"23")
msgstop(" Can't handle that entry yet")
else
nRows:= val(cDimensions) ; nCols:= nRows
endif
Enddo
DrawMatrixBoxes()
cIsActive:=iif(IsWindowActive (Form_2),"Yep","Nope") // diagnostic
MsgStop("Is Form_2 Active ? "+cIsActive)
//lFEParameter:=lIsFirstEntry
//If lIsFirstEntry
If !IsWIndowActive (Form_2)
DEFINE WINDOW Form_2 ;
AT 290,290 ;
WIDTH 400 ;
HEIGHT 300 ;
BACKCOLOR GREEN ;
TITLE "Choose Data Source"
@ 50 ,100 BUTTON Button_1 ;
PARENT Form_2;
CAPTION "Click to Use Test Values" ;
ONCLICK {||(lUseTestMatrix:=.t.,lIsFirstEntry:=.F., BackToForm_1b())} ;
WIDTH 200 ;
FONT "Arial" SIZE 12 ;
HEIGHT 35
@ 100 ,100 BUTTON Button_2 ;
PARENT Form_2;
CAPTION "Click to enter New Values" ;
ONCLICK {||(lUseTestMatrix:=.f.,lIsFirstEntry:=.F., BackToForm_1b())} ;
FONT "Arial" SIZE 12 ;
WIDTH 200 ;
HEIGHT 35
END WINDOW
ACTIVATE WINDOW Form_2
Else
Form_2.setfocus
msgstop("At end of MatrixFunStart")
Endif //lIsFIrstEntry
RETURN
Re: Re Entrant Programs- How to
Is the any memory problem when all pages defined at startupRoberto Lopez wrote: I like this scheme so much, that this is the way that JMG works (all pages defined at startup, showing each one when required).
BPD
Convert Dream into Reality through HMG
Convert Dream into Reality through HMG
- Roberto Lopez
- HMG Founder
- Posts: 4004
- Joined: Wed Jul 30, 2008 6:43 pm
Re: Re Entrant Programs- How to
I haven't any problem.bpd2000 wrote:Is the any memory problem when all pages defined at startupRoberto Lopez wrote: I like this scheme so much, that this is the way that JMG works (all pages defined at startup, showing each one when required).
The memory consumption of Windows definition is minimal.
Regards/Saludos,
Roberto
(Veritas Filia Temporis)
Roberto
(Veritas Filia Temporis)