You might recall my question not too long ago about
copy-cut-paste with toolbars. I am now looking at using nonmodal
forms. I have a couple of problems.

1) Where do I put the clear events command? If I do not have it, my
program does not terminate when all forms are closed. Since any form
might be the last, what is the best placement?

If I am using a menu, then presumably, I put it in the exit
selection, but if I am not using a menu, what do I do?

I suppose that I can have
if _screen.formcount=0 && or 1, I am not sure
clear events
endif
in a suitable event's (.unload()?) code, but it looks kludgy.

2) What is the best way to store the object references (so the forms
stay in scope)? A global array? Do you have hardcoded references to
array elements, search for a free element, or do something else?

Sincerely,

Gene Wirchenko

Re: VFP 6: clear events with Nonmodal Forms by Dan

Dan
Wed Aug 17 18:45:50 CDT 2005

Gene Wirchenko wrote:
> You might recall my question not too long ago about
> copy-cut-paste with toolbars. I am now looking at using nonmodal
> forms. I have a couple of problems.
>
> 1) Where do I put the clear events command? If I do not have it, my
> program does not terminate when all forms are closed. Since any form
> might be the last, what is the best placement?
>
> If I am using a menu, then presumably, I put it in the exit
> selection, but if I am not using a menu, what do I do?
>
> I suppose that I can have
> if _screen.formcount=0 && or 1, I am not sure
> clear events
> endif
> in a suitable event's (.unload()?) code, but it looks kludgy.

> 2) What is the best way to store the object references (so the forms
> stay in scope)? A global array? Do you have hardcoded references to
> array elements, search for a free element, or do something else?

Most folks use a Forms collection of our own in our global application
object. In my case, the app object is our only public variable.

Form classes are tweaked so that when they start up, they "announce"
themselves to the Forms collection and it knows to store a reference. When
they're releasing, they notify the forms collection so it can remove their
reference. If you used a scheme like this, your Forms collection would be
the only place you'd need to put your shutdown code.

(Although not all apps SHOULD shut down when the last form closes, of
course.)

Either way, you're going to have to find some other way to maintain counters
than _screen.Formcount because it isn't decremented until your form is
actually gone, so there isn't a way to know it got to 0 in code in the form
itself.

Dan



Re: VFP 6: clear events with Nonmodal Forms by Jack

Jack
Thu Aug 18 00:25:23 CDT 2005

On Wed, 17 Aug 2005 15:36:41 -0700, Gene Wirchenko
<genew@ucantrade.com.NOTHERE> wrote:

> You might recall my question not too long ago about
>copy-cut-paste with toolbars. I am now looking at using nonmodal
>forms. I have a couple of problems.
>
> 1) Where do I put the clear events command? If I do not have it, my
>program does not terminate when all forms are closed. Since any form
>might be the last, what is the best placement?
>
> If I am using a menu, then presumably, I put it in the exit
>selection, but if I am not using a menu, what do I do?
>
> I suppose that I can have
> if _screen.formcount=0 && or 1, I am not sure
> clear events
> endif
>in a suitable event's (.unload()?) code, but it looks kludgy.

I think that's what you have to do, put the code in the Unload()
event, except I think the test should be for formcount==1.

>
> 2) What is the best way to store the object references (so the forms
>stay in scope)? A global array? Do you have hardcoded references to
>array elements, search for a free element, or do something else?

I have a single application object with the only PUBLIC variable
holding a reference to the object. I would create an object to manage
the forms and put an instance of the object in the application object.

The form management object would at least need an array to hold the
references to the forms and an Add method. Form references are
replaced by .NULL. when the form is destroyed, so it isn't strictly
necessary to remove entries from the array when a form goes away. The
Add method could search for a NULL entry, and add a row if there isn't
one.