Re Entrant Programs- How to

Forum help and suggestions to improve this forum.

Moderator: Rathinagiri

Post Reply
bluebird
Posts: 172
Joined: Wed Sep 28, 2016 3:55 am
DBs Used: DBF

Re Entrant Programs- How to

Post by bluebird »

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
User avatar
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

Post by Rathinagiri »

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.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Re Entrant Programs- How to

Post by serge_girard »

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
	
Serge
There's nothing you can do that can't be done...
User avatar
gfilatov
Posts: 1060
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: Re Entrant Programs- How to

Post by gfilatov »

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
Hello Bluebird,

Please try the following template application: :arrow:

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 ******
Hope that helps. :idea:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Re Entrant Programs- How to

Post by Roberto Lopez »

bluebird wrote:Friends of HMG
I want to know how to make my program re-entrant.
<...>
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).

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)
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Re Entrant Programs- How to

Post by Roberto Lopez »

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:

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

I like this scheme so much, that this is the way that JMG works (all pages defined at startup, showing each one when required).
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
bluebird
Posts: 172
Joined: Wed Sep 28, 2016 3:55 am
DBs Used: DBF

Re: Re Entrant Programs- How to

Post by bluebird »

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
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Post by mol »

You should declare NoAutoRelease in form definiton
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: Re Entrant Programs- How to

Post by bpd2000 »

Roberto 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).
Is the any memory problem when all pages defined at startup
BPD
Convert Dream into Reality through HMG
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Re Entrant Programs- How to

Post by Roberto Lopez »

bpd2000 wrote:
Roberto 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).
Is the any memory problem when all pages defined at startup
I haven't any problem.

The memory consumption of Windows definition is minimal.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
Post Reply