Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Modal Forms

Status
Not open for further replies.

hayv

Programmer
Feb 27, 2001
15
CA
Hope somebody can help in solving this issue:

I have a non-modal forms, which are activated by clicking on a menu. All of these forms contain a command button that when clicked call a modal form which contains a grid that is used for record lookup. The modal form is passed a parameter that tells it the name of the file from where to pull records and returns the key of the record selected by the user to the calling form.

Now when i click the "main" close button, meaning by "main" close button the one that closes the application and returns to Windows, i get the following message:

"Cannot clear object in use", the error occurs on the main program where i have the following:

do mainmenu.prg

ON SHUTDOWN DO EXITPROC

Read Events

PROC EXITPROC
clear events
clear all
quit
ENDPROC

Curiously enough, if I click the "main" close button while in any other form, the application exits without problems and returns to Windows. That is, the error only happens on the Modal Forms called from other forms. Setting the _screen.activeform.closable = .f. and forcing the user to close the app by choosing exit from the file menu does not solve the problem because modal forms deactivate the main menu.
 
Hi my friend
I guess you using the [NAME VarName [LINKED]] in the following syntax

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

If this is the case, you assigned a pointer to your form yourself meaning you decided to have an object variable so it is your responsibility to clear it after you done use it
by issuing VarName=.NULL.

When you DO FROM without [NAME VarName [LINKED]] the VFP take the responsibility to collect its own garbage after you issuing THISFORM.RELEASE, but in this case you have to take your garbage out.
Don’t feel bad, I do this every day in the morning.

Hope I made a good guess
Thanks
Walid Magd
Engwam@Hotmail.com
 
Thanks Walid, let me check and see if this is the problem, but I dont think I am naming the form at all. Ill keep you posted
 
Walid, the problem got solved by removing the clear all statement in the ExitProc executed on shutdown, and no I was not naming the forms as I mentioned before. No the why of this behaviour is still a mystery to me.
 
Removing the CLEAR statement from you program may solve your problem to quit the program, but it doesn't remove the process from you system or free the resources used by this object. Depending on how fat this object is if you run your program more than one time and left all the resources still busy with it, you will run out if resources at any time.
Try to spend some time with this one before you ship your app.
Thanks Walid Magd
Engwam@Hotmail.com
 
Walid I replaced the Clear All statement with the following and it works. But anyway I wanted to check with you becuase after 4 months of using Fox I dont believe anything I read on Microsofts Manuals, heres the code, I think this code doesnt leave any resources pending.
PROC EXITPROC
do releaseforms
clear events
Release All Extended
Release Menus
quit
ENDPROC

PROC ReleaseForms
local lnforms, lldone
lnforms = _screen.formcount
lldone = .f.
do while lnforms > 0 and lldone
lldone = _screen.Form(lnform).queryunload()
if lldone
_screen.form(lnforms).release
lnforms = lnforms - 1
endif
enddo
ENDPROC

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top