Hao Q.


Sorry if this topic has been brought up before...

I'm working project, which I set the main window as modeless. In order to prevent the form to be released at the time of initialization, I put THIS.SHOW and Read Events in Main.Init.
However, after the form is initialized, the object main for main window is released from the memory (I view status of variables in the debugger window). If I'd like to refer to any component in the main window, all I could do is to say: THISFORM.Textbox1.....instead of saying Main.Textbox1

Besides, I have yet got an Exit menu, upon click, main window will be released. In this situation, I am not able to release window by saying Main.Release (since Main is not in memory anymore) or THISFORM.Release (this is not allowed in menu generation).

Anyone has any idea what I could do to avoid Main to be released from the memory by issuing Read Events command

Any help is greatly appreciated!


Re: why does Read Events release Main window

Naomi Nosonovsky


How exactly do you call your main form

You need to save a reference to the form somewhere. Basically, you can find your form in _screen.Forms collection. You can also add a reference to your form to some global object you're using in the application, but you would also need to release this reference when you're releasing the form.





Re: why does Read Events release Main window

Hao Q.

My main form is the the main window of the program, it's the parent window (set as top level window) of all other pop-up windows and is not invoked by any other windows.

Could you tell me how do I save a reference of the form I guess I can declare the reference as public at Main.Load so that I could use the reference later, am I correct





Re: why does Read Events release Main window

Hao Q.

I thought I figured it out. I put the following into the Formset.Load
public main
main=THISFORMSET
and now i can use main to refer to the formset. thanks a lot!




Re: why does Read Events release Main window

Naomi Nosonovsky

I was thinking you have main program and call your main form from it using DO FORM statement. Are you saying you don't have a main program If yes, probably you can go with your idea of declaring public variable in form's Load. It may work.



Re: why does Read Events release Main window

Alex Feldstein

How do you call your form

DO FORM FormName |  [NAME VarName [LINKED]] [WITH cParameterList]
 [TO VarName] [NOREAD] [NOSHOW]

See

http://msdn.microsoft.com/library/default.asp url=/library/en-us/dv_foxhelp9/html/a727f12a-4d9f-45ca-aa01-c1bea7de9749.asp frame=true

You can reference the form by: NAME VarName.

You can save the reference as a property in the calling object. You could instantiate an object to load your forms (as a Forms Manager) or you could use the _SCREEN object that holds a reference and a forms collection.

Using PUBLIC is not a good idea in an OOP architecture as it breaks encapsulation and leads to bugs.





Re: why does Read Events release Main window

dni

You need to have main form setted as modal and if you don't hide vfp windows you will not need read events in main.init.




Re: why does Read Events release Main window

Naomi Nosonovsky

I wrote a response, but now I don't see it Sad

Do you have a main program in your application calling the main form with something like DO FORM myMainForm

If yes, look at the NAME clause of DO FORM command in help.

If not, your idea of using Main form's Load and global variable may work. I haven't tried this before.





Re: why does Read Events release Main window

Alex Feldstein

Hao Q. wrote:
I thought I figured it out. I put the following into the Formset.Load
public main
main=THISFORMSET
and now i can use main to refer to the formset. thanks a lot!

FormSets are not a good idea. And declaring them PUBLIC is not a good idea either (see above)..

Do not use FormSets. Use a main form instead.

See:
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=261598&SiteID=1
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1159346&SiteID=1





Re: why does Read Events release Main window

Naomi Nosonovsky

Never worked with formsets since I know they cause nothing but troubles <g>



Re: why does Read Events release Main window

Naomi Nosonovsky

Off-topic. I don't understand how does this forum work. I saw several responses in this thread, but now again I only see 3 responses and few of mine are gone as well.

How can I disable Alerts globally Right now I have to uncheck the Alert button every time and if I forget, it brings this new Alert page and after pressing Cancel the message is gone...





Re: why does Read Events release Main window

CetinBasoz

What is wrong with "thisform"

In exit routine you could clear events and loop existing forms using _vfp.objects collection.

You might as well keep references in a custom oApp object that's created on entry (might also use _screen for this but I prefer custom oApp as you can also create application wide methods there).





Re: why does Read Events release Main window

Hao Q.

Thanks, your solution is correct, just declare a public variable at Form Load.

Others' suggestions would be correct too, it's just this is the fastest way to solve my current problem, since my project has been finished, and it's quite big, i don't want to modify lots of code to resolve this issue.




Re: why does Read Events release Main window

Hao Q.

I have to set main form as modeless, since i have menus in main window. the menu would be disabled if main form is set to modal.

The problem I'm having now is how do I release the main window. What I'm doing is shown as follow:

--In main.init:
THIS.SHOW
READ EVENTS

THISFORM.Release
Release All && isn't this line supposed to release all variables it seems not working for me, any idea

--Exit.Click
Clear Events && this will force the program go back to line right after Read Events in Main.Init

The above approach doesn't seem to be working, any idea about it Thanks!




Re: why does Read Events release Main window

Hao Q.

Ya, I realized using formset brings quite a bit trouble. I'm still a Foxpro newbie, I saw my supervisor using it a lot, so I tried to follow the same style. Then I realized the reason my supervisor is still using it is b/c he used to be Dos Foxpro developer for years, and he needs a lot of back compatibility that formset can give him. So... I guess I will be using form instead of formset from now on. Appreciate your help!