|
Home > Archive > dBASE Programming > February 2006 > Closing forms
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| I would like to close certain forms after a period of inactivity. FormA is nonmodal and it calls formB which is modal. I set up a timer and if the elapsed time is > 45 minutes, I use findinstance to see if form b is open, and close it if it is. Then I
use findinstance to see if formA is open, and close it if it is.
Problem is, formB closes fine, but fomrA stays open. Anyone have an idea of why and what I could do differently?
Thanks for any ideas. Code I use is below.
Rick
FUNCTION CheckTableTime(Lnotify_)
* Purpose: This runs if the interval for autotables close was reached.
//- if so, close out the notes and staff
* first modal forms if they are open
LOCAL f
* modal form child of FORMA
f = findinstance("FORMBFORM")
if not empty( f )
f.windowstate=0
f.setfocus()
f.close()
endif
form.setfocus()
* nonmodal form that is parent of FORMB
f = findinstance("FORMAFORM")
if not empty( f )
f.windowstate=0
f.setfocus()
f.close()
endif
form.setfocus()
form.txtwarning.visible:=false
RETURN true
| |
| Michael Nuwer [dBVIPS] 2006-02-11, 6:03 pm |
|
For some reason closing the modal form terminates the funtion before it
gets to the second findInstance test. When I ran the code below with
your form-closing sequence, I got the same result as you. But if I close
formB first, then formA it works. The following code, all run from ONE
prg file, seems to work.
local a,f
a = new App()
//set procedure to formA.wfm addi
f=new formAform()
f.open()
f.pushbutton1_onClick()
class app
this.timer = new Timer()
//this.timer.app = this
this.timer.interval := 10
this.timer.onTimer := class::Timer_OnTimer
this.timer.enabled := True
function timer_OnTimer
LOCAL f
* nonmodal form that is parent of FORMB
f = findinstance("FORMAFORM")
? "two"+not empty( f )
if not empty( f )
f.windowstate=0
f.setfocus()
f.close()
endif
//form.setfocus()
?"here"
* modal form child of FORMA
f = findinstance("FORMBFORM")
? "one" + not empty( f )
if not empty( f )
f.windowstate=0
f.setfocus()
f.close()
endif
//form.setfocus()
endclass
class formaForm of FORM
this.PUSHBUTTON1 = new PUSHBUTTON(this)
with (this.PUSHBUTTON1)
onClick = class::PUSHBUTTON1_ONCLICK
text = "Pushbutton1"
endwith
function PUSHBUTTON1_onClick
local f
//set procedure to formb.wfm addi
f=new formbform()
f.mdi=false
f.readModal()
return
endclass
class formbForm of FORM
this.ENTRYFIELD1 = new ENTRYFIELD(this)
with (this.ENTRYFIELD1)
value = "Entryfield1"
endwith
endclass
Rick wrote:
> I would like to close certain forms after a period of inactivity. FormA is nonmodal and it calls formB which is modal. I set up a timer and if the elapsed time is > 45 minutes, I use findinstance to see if form b is open, and close it if it is. Then
I use findinstance to see if formA is open, and close it if it is.
>
> Problem is, formB closes fine, but fomrA stays open. Anyone have an idea of why and what I could do differently?
>
> Thanks for any ideas. Code I use is below.
>
> Rick
>
> FUNCTION CheckTableTime(Lnotify_)
> * Purpose: This runs if the interval for autotables close was reached.
> //- if so, close out the notes and staff
> * first modal forms if they are open
>
> LOCAL f
>
> * modal form child of FORMA
> f = findinstance("FORMBFORM")
> if not empty( f )
> f.windowstate=0
> f.setfocus()
> f.close()
> endif
> form.setfocus()
>
> * nonmodal form that is parent of FORMB
> f = findinstance("FORMAFORM")
> if not empty( f )
> f.windowstate=0
> f.setfocus()
> f.close()
> endif
> form.setfocus()
> form.txtwarning.visible:=false
>
>
> RETURN true
>
>
| |
| Robert Bravery 2006-02-12, 7:46 am |
| HI,
As I understand, you are opening form b from form a, with a refernce to
formb in form a
Two things because formb is modal, you cant have any user action outside of
it,
Two everything, after the call from form a to fromb halts until formb is
closed.
I think that the find instance, is creating a circularreference, andother
instance of form b, you closing f.formb, but form a is still at the opening
point. But if you close forma.formb, then it should work.
Robert
"Rick" <Sportman7@netzero.com> wrote in message
news:vUq$9T1LGHA.1148@news-server...
> I would like to close certain forms after a period of inactivity. FormA
is nonmodal and it calls formB which is modal. I set up a timer and if the
elapsed time is > 45 minutes, I use findinstance to see if form b is open,
and close it if it is. Then I use findinstance to see if formA is open, and
close it if it is.
>
> Problem is, formB closes fine, but fomrA stays open. Anyone have an idea
of why and what I could do differently?
>
> Thanks for any ideas. Code I use is below.
>
> Rick
>
> FUNCTION CheckTableTime(Lnotify_)
> * Purpose: This runs if the interval for autotables close was
reached.
> //- if so, close out the notes and staff
> * first modal forms if they are open
>
> LOCAL f
>
> * modal form child of FORMA
> f = findinstance("FORMBFORM")
> if not empty( f )
> f.windowstate=0
> f.setfocus()
> f.close()
> endif
> form.setfocus()
>
> * nonmodal form that is parent of FORMB
> f = findinstance("FORMAFORM")
> if not empty( f )
> f.windowstate=0
> f.setfocus()
> f.close()
> endif
> form.setfocus()
> form.txtwarning.visible:=false
>
>
> RETURN true
>
>
| |
|
| Michael,
Yes, the findinstance and closing of the modal form seems to prevent the code from executing from that point in my code. In fact, I have a line of code that makes a warning message disappear at the end of my code that also never gets executed.
While I confirmed your code works, I must have something else going on in my code. After rearranging findinstance/closings to close nonmodal parent form first, I get very strange results.
Despite the sequence in the code, the nonmodal parent form I close first does not close, and the modal child does. From that point, none of the remaining code gets executed once the modal form closes.
Will have to take your code and fold in some of mine to see what is going on. If you have any ideas, let me know.
Thanks again,
Rick
Michael Nuwer [dBVIPS] Wrote:
[vbcol=seagreen]
>
> For some reason closing the modal form terminates the funtion before it
> gets to the second findInstance test. When I ran the code below with
> your form-closing sequence, I got the same result as you. But if I close
> formB first, then formA it works. The following code, all run from ONE
> prg file, seems to work.
>
>
>
> local a,f
> a = new App()
> //set procedure to formA.wfm addi
> f=new formAform()
> f.open()
> f.pushbutton1_onClick()
>
> class app
> this.timer = new Timer()
> //this.timer.app = this
> this.timer.interval := 10
> this.timer.onTimer := class::Timer_OnTimer
> this.timer.enabled := True
>
>
> function timer_OnTimer
> LOCAL f
> * nonmodal form that is parent of FORMB
> f = findinstance("FORMAFORM")
> ? "two"+not empty( f )
> if not empty( f )
> f.windowstate=0
> f.setfocus()
> f.close()
> endif
> //form.setfocus()
> ?"here"
>
> * modal form child of FORMA
> f = findinstance("FORMBFORM")
> ? "one" + not empty( f )
> if not empty( f )
> f.windowstate=0
> f.setfocus()
> f.close()
> endif
> //form.setfocus()
> endclass
>
> class formaForm of FORM
>
> this.PUSHBUTTON1 = new PUSHBUTTON(this)
> with (this.PUSHBUTTON1)
> onClick = class::PUSHBUTTON1_ONCLICK
> text = "Pushbutton1"
> endwith
> function PUSHBUTTON1_onClick
> local f
> //set procedure to formb.wfm addi
> f=new formbform()
> f.mdi=false
> f.readModal()
> return
>
> endclass
>
> class formbForm of FORM
>
> this.ENTRYFIELD1 = new ENTRYFIELD(this)
> with (this.ENTRYFIELD1)
> value = "Entryfield1"
> endwith
>
> endclass
>
>
>
>
>
> Rick wrote:
n I use findinstance to see if formA is open, and close it if it is.[vbcol=seagreen]
| |
|
| Hi Robert,
Robert Bravery Wrote:
> HI,
> As I understand, you are opening form b from form a, with a refernce to
> formb in form a
Yes. Exactly.
>
> Two things because formb is modal, you cant have any user action outside of
> it,
> Two everything, after the call from form a to fromb halts until formb is
> closed.
Yes, that would explain my most recent post to Michael. When I change the sequence trying to close form a (nonmodal) first, it is ignored and only form b (modal) is closed. Tho it seems strange that execution of the remaining code in that function is s
topped.
> I think that the find instance, is creating a circularreference, andother
> instance of form b, you closing f.formb, but form a is still at the opening
> point. But if you close forma.formb, then it should work.
Not sure what you mean here. Do you mean to close forma first then form b? When I do so I get some strange results as in my post to Michael. Or do you mean that since forma is the parent of formb, I should close form b somehow through forma, then close
form a? Not sure what the code would look like here, could you give me an example?
Thanks again for any ideas,
Rick
>
> Robert
>
> "Rick" <Sportman7@netzero.com> wrote in message
> news:vUq$9T1LGHA.1148@news-server...
> is nonmodal and it calls formB which is modal. I set up a timer and if the
> elapsed time is > 45 minutes, I use findinstance to see if form b is open,
> and close it if it is. Then I use findinstance to see if formA is open, and
> close it if it is.
> of why and what I could do differently?
> reached.
>
>
| |
| Robert Bravery 2006-02-13, 2:50 am |
| HI Rick,
>
> Not sure what you mean here. Do you mean to close forma first then form
b? When I do so I get some strange results as in my post to Michael. Or do
you mean that since forma is the parent of formb, I should close form b
somehow through forma, then close form a? Not sure what the code would look
like here, could you give me an example?
Yes. I would put the timeer in forma, and since I open the form b in form a
I would close the form b from within for a
In the ontimerevent of forma
form.formb.close()
Robert
| |
| Andrew Shimmin 2006-02-13, 7:48 am |
| Rick,
Try the attached.
regards, andrew
Rick wrote:
> I would like to close certain forms after a period of inactivity. FormA is nonmodal and it calls formB which is modal. I set up a timer and if the elapsed time is > 45 minutes, I use findinstance to see if form b is open, and close it if it is. Then
I use findinstance to see if formA is open, and close it if it is.
>
> Problem is, formB closes fine, but fomrA stays open. Anyone have an idea of why and what I could do differently?
>
> Thanks for any ideas. Code I use is below.
>
> Rick
>
> FUNCTION CheckTableTime(Lnotify_)
> * Purpose: This runs if the interval for autotables close was reached.
> //- if so, close out the notes and staff
> * first modal forms if they are open
>
> LOCAL f
>
> * modal form child of FORMA
> f = findinstance("FORMBFORM")
> if not empty( f )
> f.windowstate=0
> f.setfocus()
> f.close()
> endif
> form.setfocus()
>
> * nonmodal form that is parent of FORMB
> f = findinstance("FORMAFORM")
> if not empty( f )
> f.windowstate=0
> f.setfocus()
> f.close()
> endif
> form.setfocus()
> form.txtwarning.visible:=false
>
>
> RETURN true
>
>
| |
|
| Andrew,
Thanks. I have a main menu form that calls all forms, and that is where I would like the timer to be to check on inactivity and then close any forms, including child and grandchild. Global reference may be the best (and maybe the only) way to do this for
the modal forms.
I may set up a global object and attach modal forms to that object. Then I can iterate through the attached forms and close each one from the main menu.
Thanks again,
Rick
Andrew Shimmin Wrote:
> Rick,
>
> Try the attached.
>
> regards, andrew
>
> Rick wrote:
n I use findinstance to see if formA is open, and close it if it is.[vbcol=seagreen]
>
> ** END HEADER -- do not remove this line
> //
> // Generated on 13/02/2006
> //
> parameter bModal
> local f
> f = new FormAForm()
> if (bModal)
> f.mdi = false // ensure not MDI
> f.readModal()
> else
> f.open()
> endif
>
> class FormAForm of FORM
> with (this)
> onOpen = class::FORM_ONOPEN
> onClose = class::FORM_ONCLOSE
> height = 2.7273
> left = 84.8571
> top = 21.8182
> width = 28.7143
> text = ""
> autoSize = false
> autoCenter = true
> mdi = false
> smallTitle = true
> endwith
>
> this.PUSHBUTTON1 = new PUSHBUTTON(this)
> with (this.PUSHBUTTON1)
> onClick = class::PUSHBUTTON1_ONCLICK
> height = 1.0909
> left = 6.8571
> top = 0.5
> width = 15.2857
> text = "Open FormB"
> endwith
>
>
> function PUSHBUTTON1_onClick
>
> this.parent.oTimer.enabled := true // turn on timer
> _app.oModalFormB := NEW FormBForm() // instantiate formB
> _app.oModalFormB.readModal() // run formB
> _app.oModalFormB := null // stub-out formB object reference
> this.parent.oTimer.enabled := false // turn off timer
>
> return
>
> function form_onOpen
>
> SET PROCEDURE TO FormB.wfm ADDITIVE
>
> this.text := "FormA"
>
>
> _app.oModalFormA = this // application property for formA object reference
> _app.oModalFormB = "" // application property for formB object reference
>
> this.oTimer = NEW TIMER()
> this.oTimer.parent = this
> this.oTimer.onTimer = class::checkFormB // onTimer event handler
>
> this.oTimer.interval := 5 // 5 seconds
> this.oTimer.enabled := false
>
> return
>
> function checkFormB()
>
> IF .not.EMPTY(_app.oModalFormB) // formB active?
> _app.oModalFormB.close() // close it
> this.enabled := false // turn timer off
> ENDIF
>
> return
>
> function form_onClose
>
> this.release()
>
> return
>
> endclass
>
>
> ** END HEADER -- do not remove this line
> //
> // Generated on 13/02/2006
> //
> parameter bModal
> local f
> f = new FormBForm()
> if (bModal)
> f.mdi = false // ensure not MDI
> f.readModal()
> else
> f.open()
> endif
>
> class FormBForm of FORM
> with (this)
> onOpen = class::FORM_ONOPEN
> onClose = class::FORM_ONCLOSE
> height = 2.3182
> left = 67.1429
> top = 7.5909
> width = 29.5714
> text = ""
> autoSize = false
> autoCenter = true
> mdi = false
> smallTitle = true
> endwith
>
> this.PUSHBUTTON1 = new PUSHBUTTON(this)
> with (this.PUSHBUTTON1)
> onClick = class::PUSHBUTTON1_ONCLICK
> height = 1.0909
> left = 6.8571
> top = 0.5
> width = 15.2857
> text = "Close"
> endwith
>
> function PUSHBUTTON1_onClick
>
> form.close()
>
> return
>
> function form_onClose
>
> this.release()
>
> return
>
> function form_onOpen
>
> this.text := "FormB"
>
> return
>
> endclass
>
>
| |
|
| Robert,
Would like to do the timer in my main menu form rather than every form that opens from there. May set up a global object for modal forms and use it to close those child and grandchild forms opened from the main menu.
Thanks again,
Rick
Robert Bravery Wrote:
> HI Rick,
>
> b? When I do so I get some strange results as in my post to Michael. Or do
> you mean that since forma is the parent of formb, I should close form b
> somehow through forma, then close form a? Not sure what the code would look
> like here, could you give me an example?
>
> Yes. I would put the timeer in forma, and since I open the form b in form a
> I would close the form b from within for a
>
> In the ontimerevent of forma
> form.formb.close()
>
> Robert
>
>
| |
| Robert Bravery 2006-02-14, 5:51 pm |
| HI Rick,
It really depends on whats holding the reference to the formb, and from
where your opening it. The question is, does processing have to stop at a
certain point in forma, when formb is opened and then resume. If you don't
have this limitation, then I guess you could open it anywhere
Robert
"Rick" <Sportman7@netzero.com> wrote in message
news:cCUVPDZMGHA.560@news-server...
> Robert,
>
> Would like to do the timer in my main menu form rather than every form
that opens from there. May set up a global object for modal forms and use
it to close those child and grandchild forms opened from the main menu.
>
> Thanks again,
> Rick
>
> Robert Bravery Wrote:
>
form[vbcol=seagreen]
Or do[vbcol=seagreen]
look[vbcol=seagreen]
form a[vbcol=seagreen]
>
| |
|
| Robert,
I think I understand. What I will attempt is to create a global object in my main menu. Whenever a nonmodal child of the main menu form opens a grandchild modal form, I will use this global object to hold the reference instead of using the child form as
I do now. Theoretically, then my timer in the main menu should be able to close these modal grandchild forms thru the global object. I could even avoid using findinstance to see if the modal form is open and just iterate through the global object and cl
ose each attached modal form.
Does that sound right to you?
Thanks again,
Rick
Robert Bravery Wrote:
> HI Rick,
> It really depends on whats holding the reference to the formb, and from
> where your opening it. The question is, does processing have to stop at a
> certain point in forma, when formb is opened and then resume. If you don't
> have this limitation, then I guess you could open it anywhere
>
> Robert
>
> "Rick" <Sportman7@netzero.com> wrote in message
> news:cCUVPDZMGHA.560@news-server...
> that opens from there. May set up a global object for modal forms and use
> it to close those child and grandchild forms opened from the main menu.
> form
> Or do
> look
> form a
>
>
| |
| Andrew Shimmin 2006-02-15, 7:50 am |
| Rick,
Checking for form inactivity is a completely different kettle of fish. Have a look at the attached.
I built a custom form class that has the timer for monitoring inactivity in the custom form class definition. The drived form simply has calls to a custom form class function to log any activity. The timer simply checks for any inactivity longer than what
you set.
This approach provides encapsulation in the child forms for their inactivity monitoring and close control.
regards, andrew
Rick wrote:
> Andrew,
>
> Thanks. I have a main menu form that calls all forms, and that is where I would like the timer to be to check on inactivity and then close any forms, including child and grandchild. Global reference may be the best (and maybe the only) way to do this f
or the modal forms.
>
> I may set up a global object and attach modal forms to that object. Then I can iterate through the attached forms and close each one from the main menu.
>
> Thanks again,
> Rick
| |
|
| Andrew,
I like your kettle of fish<g>. Will have to take a closer look and maybe revamp my setup.
Thanks,
Rick
Andrew Shimmin Wrote:
> Rick,
>
> Checking for form inactivity is a completely different kettle of fish. Have a look at the attached.
>
> I built a custom form class that has the timer for monitoring inactivity in the custom form class definition. The drived form simply has calls to a custom form class function to log any activity. The timer simply checks for any inactivity longer than wh
at you set.
>
> This approach provides encapsulation in the child forms for their inactivity monitoring and close control.
>
> regards, andrew
>
> Rick wrote:
for the modal forms.[vbcol=seagreen]
>
> ** END HEADER -- do not remove this line
> //
> // Generated on 13/02/2006
> //
> parameter bModal
> local f
> f = new MasterForm()
> if (bModal)
> f.mdi = false // ensure not MDI
> f.readModal()
> else
> f.open()
> endif
>
> class MasterForm of FORM
> with (this)
> onOpen = class::FORM_ONOPEN
> onClose = class::FORM_ONCLOSE
> height = 2.7273
> left = 84.8571
> top = 21.8182
> width = 28.7143
> text = "MasterForm"
> autoSize = false
> autoCenter = true
> mdi = true
> smallTitle = true
> endwith
>
> this.PUSHBUTTON1 = new PUSHBUTTON(this)
> with (this.PUSHBUTTON1)
> onClick = class::PUSHBUTTON1_ONCLICK
> height = 1.0909
> left = 6.8571
> top = 0.5
> width = 15.2857
> text = "Open ChildForm"
> endwith
>
>
> function PUSHBUTTON1_onClick
>
> _app.oModalChildForm := NEW ChildForm() // instantiate ChildForm
> _app.oModalChildForm.dtLastActivity = "" // create property for last activity for any control on the form
>
> _app.oModalChildForm.readModal() // run ChildForm
>
> _app.oModalChildForm := null // stub-out ChildForm object reference
>
> return
>
> function form_onOpen
>
> SET PROCEDURE TO ChildForm.wfm ADDITIVE
>
> _app.nTimerInterval = 10 // form activity timer interval
> _app.oMasterForm = this // application property for MasterForm object reference
> _app.oModalChildForm = "" // application property for ChildForm object reference
>
> return
>
> function form_onClose
>
> this.release()
>
> return
>
> endclass
>
>
>
>
> class ChildFormsCForm of FORM custom
> with (this)
> onOpen = class::FORM_ONOPEN
> height = 7.9545
> left = 73.7143
> top = 8.6818
> width = 38.4286
> text = "ChildForm"
> autoCenter = true
> mdi = false
> smallTitle = true
> maximize = false
> endwith
>
>
> function form_onOpen
>
> this.oDate = NEW DATE() // instantiate date object for activity interval checking
>
> this.oTimer = NEW TIMER()
> this.oTimer.parent = this
> this.oTimer.onTimer = class::checkFormActivity // onTimer event handler
> this.oTimer.interval := _app.nTimerInterval // set timer interval
> this.oTimer.enabled := true // start timer
>
> return
>
> Function common_when(bOpen)
> //
> // Function to manage derived (child) form controls for activity.
> // ALL (or the ones you want) drived form controls MUST have the
> // call to this function as the first line of code in the when()
> // event handlers.
> //
>
> form.dtLastActivity := DATETIME() // time stamp this activity
>
> return
>
> Function checkFormActivity()
> // get current time stamp
> now = DATETIME()
>
> TimeNow = this.parent.oDate.parse(DTTOC(now)) // get milliseconds for now
> TimeLastActivity = this.parent.oDate.parse(DTTOC(this.parent.dtLastActivity)) // get milliseconds for last activity
>
> IF (TimeNow-TimeLastActivity)/1000 > _app.nTimerInterval // no activity in last timer interval?
> this.enabled := false // stop timer
> this.parent.close() // close form
> ELSE
> this.enabled := true // go again
> ENDIF
>
> return
>
> endclass
>
>
> ** END HEADER -- do not remove this line
> //
> // Generated on 15/02/2006
> //
> parameter bModal
> local f
> f = new ChildForm()
> if (bModal)
> f.mdi = false // ensure not MDI
> f.readModal()
> else
> f.open()
> endif
>
> class ChildForm of CHILDFORMSCFORM from "ChildForms.cfm"
> with (this)
> onOpen = class::FORM_ONOPEN
> onClose = class::FORM_ONCLOSE
> height = 6.0909
> left = 80.2857
> top = 17.7273
> width = 25.0
> text = "ChildForm"
> endwith
>
> this.PUSHBUTTON1 = new PUSHBUTTON(this)
> with (this.PUSHBUTTON1)
> onClick = class::PUSHBUTTON1_ONCLICK
> height = 1.0909
> left = 6.8571
> top = 4.0
> width = 10.7143
> text = "Close"
> endwith
>
> this.TOUCHME = new ENTRYFIELD(this)
> with (this.TOUCHME)
> when = class::TOUCHME_WHEN
> height = 1.0
> left = 7.2857
> top = 0.5
> width = 10.7143
> value = "Touch me!"
> endwith
>
> this.PUSHME = new PUSHBUTTON(this)
> with (this.PUSHME)
> when = class::PUSHME_WHEN
> height = 1.0909
> left = 7.2857
> top = 2.0
> width = 10.7143
> text = "Push me!"
> endwith
>
>
> function form_onOpen
>
> SUPER::form_onOpen() // create and start inactivity timer
>
> // do whatever you want here for this form
>
> return
>
> function PUSHBUTTON1_onClick
>
> form.close()
>
> return
>
> function TOUCHME_when(bOpen)
>
> SUPER::common_when(bOpen)
// log this activity
>
> // do whatever you want here for this control
>
> return true
>
> function PUSHME_when(bOpen)
>
> SUPER::common_when(bOpen)
// log this activity
>
> // do whatever you want here for this control
>
> return true
>
> function form_onClose
>
> this.release()
>
> return
>
> endclass
>
>
| |
| Andrew Shimmin 2006-02-17, 10:51 pm |
| Rick,
OK. You are better off keeping as much as you can in the child forms. That way the need for multi-form co-ordination is minimised.
regards, andrew
Rick wrote:
> Andrew,
>
> I like your kettle of fish<g>. Will have to take a closer look and maybe revamp my setup.
>
> Thanks,
> Rick
|
|
|
|
|