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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form not releasing 1

Status
Not open for further replies.

SnyAc

Programmer
Jul 25, 2001
272
US
I have been having a problem with a simple form not releasing.
It is a modal form that only has a listbox control in it. The listbox rowsource is selected fields from a table. The form's release method executes and the close box dims, program execution continues, but the form is still on the screen and won't clear.

Any ideas?

Thanks in advance....

Andy Snyder
SnyAc Software Services
 
Andy,

I am having similar problems.

To close the form I am trying

USE the cursor - used in a grid on the form - works - grid dissappears.
USE a currently OPEN table which is modified during a procedure in a grid button.click on my form.
thisform.RELEASE
thisform.DESTROY

AS you say program execution continues - the form stays on screen


See thread1254-1385616

Regards

Bryan

 
Andy,

This sounds like a dangling object reference.

How are you instantiating the form? Do you have some code somewhere that does a CreateObject or a NewObject, and then stores the object reference in some variable or property? In other words, you've got more than one reference to form in existence?

If so, you need to make sure that all the references are properly cleared. You can test for this by just running the form on its own. If it closes OK, then the above diagnosis is likely to be correct.

If the problem persists, it's likely that the form is instantiating some other object and not releasing it. Have you got any code in the form that might be doing that, for example, the form does a NewObject and stores the object reference somewhere externally?

Also, when you have a list box or combo box that is populated from a table, it's a good idea always to close the table when you close the form. I don't think it will help with the current problem, but it could cause a different kind of error if you don't do that.

Bryan,

I don't think this is related to the problem, but you don't want to call both the Release and the Destroy. Just do the Release. The Destroy gets fired automatically.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,

Thanks for that.

I was simply trying as many ways of addressing the form that were at all possible to try and close it.

In the debugger I see my oform object set to NULL after the first thisform.release() but it still remains on screen.

It is sitting over Form 2 produced from the following sequence.

- mainform with a pageframe on page 5

- (code to produce a table for a grid1)

- a hand coded form1 with a grid1 - a click on a cell to do a procedure

-(code to produce a table for a grid2)

- a hand coded form2 with a grid2

- a click on a cell to do a procedure changing a value in the table underlying form1/grid1

-ending in the release() method to clear this form and allow another operation on Form 1

Apart from in the debugger is it possible to write out to my log file the names of the objects that exist at the point I want to close this form.

This is the last step in a long and involved sequence of operations for the user and without this form going away this important facility of my app can't be implemented.

Regards

Bryan
 
Bryan,

I feel sure that you are somewhere storing a reference to one of your forms, and that reference is not being cleared when you try to close the form. But without seeing the relevant code, it's difficult to know.

Apart from in the debugger is it possible to write out to my log file the names of the objects that exist at the point I want to close this form.

You could write a function that does that, using AMEMBERS(). But I'm not sure it would be worth the effort. It might be better to concentrate on the code that's creating and storing the objects.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,

I hope this isn't too long!

Code:
*******************************************************************

*** Name.....: browse_replacement


*** Function.: Show possible replacement exhibits - non image


*** Called From: getfiles2
********************************************************************
PUBLIC oForm


logging('gsbrowse_replacement')

DECLARE INTEGER ShellExecute ;
	IN SHELL32.DLL ;
	INTEGER nWinHandle,;
	STRING cOperation,;
	STRING cFileName,;
	STRING cParameters,;
	STRING cDirectory,;
	INTEGER nShowWindow



if !used('foundex')


USE foundexh IN 0

endif

SELECT foundexh

SELECT * FROM foundexh  INTO TABLE mycursor

SELECT foundexh

USE

SELECT mycursor

SET DEFAULT TO (mysystempath) 

DO openings -&& check for open tables

SET DEFAULT TO (mydatapath) 

GO TOP

oForm = CREATEOBJECT("EDITOR")

oForm.SHOW()

RETURN


DEFINE CLASS EDITOR AS FORM

	TOP = 0
	LEFT = 0
	HEIGHT = 450
	WIDTH =700
	BACKCOLOR = RGB(192,192,192)
	DOCREATE = .T.
	CAPTION = 'New exhibit Selection'
	NAME = "MyForm2"
	ICON = 'pw16_1.ico'
	AUTOCENTER = .T.
	MOVABLE = .F.
	CONTROLBOX = .F.
	SHOWTIPS = .T.




	ADD OBJECT cmdExit AS COMMANDBUTTON WITH ;
		TOP = 420, ;
		LEFT = 550, ;
		HEIGHT = 27, ;
		WIDTH = 84, ;
		FONTBOLD = .T. ,;
		FORECOLOR = RGB(255,0,0), ;
		CAPTION ='Exit' ,;
		NAME = "cmdExit"

	ADD OBJECT cmdList AS COMMANDBUTTON WITH ;
		TOP = 420, ;
		LEFT = 450, ;
		HEIGHT = 27, ;
		WIDTH = 84, ;
		FONTBOLD = .T. ,;
		FORECOLOR = RGB(255,0,0), ;
		CAPTION ='List' ,;
		NAME = "cmdList"

	ADD OBJECT helplable AS LABEL WITH ;
		TOP = 410, ;
		LEFT = 10, ;
		HEIGHT = 27, ;
		WIDTH = 400, ;
		CAPTION = 'Click fullpath to select,Memo to view contents and P/O to Play/Open' ,;
		BACKCOLOR = RGB(192,192,192)  , ;
		FORECOLOR = RGB(255,0,0), ;
		FONTBOLD = .T., ;
		NAME = "helplable "



	ADD OBJECT grid1 AS GRID WITH ;
		HEIGHT = 400, ;
		LEFT = 4, ;
		TOP = 4, ;
		WIDTH = 650, ;
		READONLY=.F., ;
		ROWHEIGHT = 20,;
		DELETEMARK = .F. ,;
		RECORDSOURCE = "" , ;
		COLUMNCOUNT = -1,;
		CAPTION = 'Select Replacement' ,;
		ROWHEIGHT = 22 ,;
		NAME = "Grid1"


	PROCEDURE INIT  &&  form init - this is first after form opened


	logging('gsbrowse_replacement - init')

	ENDPROC

	PROCEDURE  grid1.INIT


	THIS.RECORDSOURCE = "mycursor"

	WITH THIS.Column1
		.Header1.CAPTION =  'Fullpath'
		.CONTROLSOURCE = 'mycursor.FULL_PATH'
		.ADDOBJECT("mycmd","make_repl") && fname2
		.WIDTH = 450
		.MOVABLE = .F.
		.READONLY = .T.
		.FONTBOLD = .T.
		.CURRENTCONTROL = "mycmd"
		.VISIBLE  = .T.

	ENDWITH

	THISFORM.grid1.ADDOBJECT('Column2','Column')

	WITH THIS.Column2
		.Header1.CAPTION =  'P/O'
		.CONTROLSOURCE = 'mycursor.PLAY'
		.ADDOBJECT("mycmd","play_repl") && fname2
		.WIDTH = 40
		.MOVABLE = .F.
		.READONLY = .T.
		.FONTBOLD = .T.
		.ForeColor = Rgb(0,0,255)
		.BackColor= Rgb(255,255,255)
		.CURRENTCONTROL = "mycmd"
		.VISIBLE  = .T.
	ENDWITH

	THISFORM.grid1.ADDOBJECT('Column3','Column')

	WITH THIS.Column3
		.CONTROLSOURCE = 'mycursor.FILESIZE'
		.Header1.CAPTION = 'FSIZE'
		.VISIBLE  = .T.
		.WIDTH = 70
		.MOVABLE = .F.
		.READONLY = .T.
		.FONTBOLD = .T.

	ENDWITH

	ENDPROC



	PROCEDURE  cmdExit.CLICK   &&  <<<<<<<<<<<<<<<<<<<<<<<<<  EXIT  <<<<<<<<<<<<<<<<<<<<<<<<<<<



	THISFORM.RELEASE
	THISFORM.DESTROY

	ENDPROC

	PROCEDURE  cmdList.CLICK   &&  <<<<<<<<<<<<<<<<<<<<<<<<<  LIST<<<<<<<<<<<<<<<<<<<<<<<<<<<

	

	ENDPROC


*!*	****************************************************************



ENDDEFINE

DEFINE CLASS play_repl AS  TEXTBOX


	READONLY =.F.

	PROCEDURE CLICK

	myfile = mycursor.full_path



	SET DEFAULT TO (mysystempath)

	cAction = "open"

	ShellExecute(0,cAction,myfile ,"","",1)

*!*		DO gsbrowse_all

	ENDPROC
ENDDEFINE



DEFINE CLASS make_repl  AS  TEXTBOX  && this is the image selection

	READONLY =.F.

	PROCEDURE CLICK

	SET DEFAULT TO (mysystempath)


	cMessageText = 'Are you sure you want to replace the exhibit?'

	nAnswer = MyMsgBox(cMessageText, cMessageButtons1,cMsgTitle)

	IF nAnswer = 1

		SELECT EDITING_

		logging(ALIAS())


		newexh = mycursor.full_path

		IF !EMPTY(newpic)

			REPLACE FNAME2 WITH JUSTFNAME(newexh )
			
			REPLACE NEWPATH WITH JUSTPATH(newexh )
			
			REPLACE up_dated WITH .T.

			isupdated = .T.


		ENDIF

	ENDIF

	SELECT EDITING_

	USE

	USE IN SELECT("MyCursor")

	THISFORM.RELEASE
	THISFORM.DESTROY

	myForm2.RELEASE()
	myForm2 = .NULL.

	oForm.RELEASE()
	oForm = .NULL.

	ENDPROC

ENDDEFINE

Regards

Bryan
 
Bryan,

Off-hand, I can't see anything in your code that would cause this problem.

I'm a little worried about the code in your make_rep1 class:

Code:
   THISFORM.RELEASE
    THISFORM.DESTROY

    myForm2.RELEASE()
    myForm2 = .NULL.

    oForm.RELEASE()
    oForm = .NULL.

I can't see how this would work. It should be enough just to do a THISFORM.Release. I assume you put all the extra stuff in there because the Release wasn't working.

Let me ask you this: Does the problem arise only when you click on the make_rep1 control (in other words, when the above code executes)? Or also when you click on your exit button? What about if you click on the X button on the title bar?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hi Mike,

Thanks for your reply.

I have tried several things.

1 I made CONTROLBOX = .T. and when the form was presented the X closed it OK.

2 I removed the USE editing_ after the make_repl procedure and removed the release().

3 I added DO domygrid which runs (reruns)the grid on Form1 after that procedure on a cursor based on EDITING_.

4 Form2 (oform) disappears

5 I see my new entries as required.

6 I can do another operation in that form as I wanted to.

However the oform is still a live object although not visible on screen.



7 When I exit Form1 I see the Form2 and cannot EXIT

Some progress....

Next step is to leave the

oForm.RELEASE()
oForm = .NULL.
in form2

Voila! Exit from Form1 takes me back to the PageFrame I started from as I want.



But what reservations do you have on the make_repl procedure?

Regards

Bryan

 
Bryan,

My reservation was that, in the following code:

THISFORM.RELEASE
THISFORM.DESTROY

myForm2.RELEASE()
myForm2 = .NULL.

oForm.RELEASE()
oForm = .NULL.

THISFORM, MyForm2 and oForm all refer to the same object. So you were calling the RELEASE of the same object three times, even though the object no longer exists after the first call.

That said, I don't think that's directly related to the problem. I would remove everything after the THISFORM.Release, but I don't say that would solve the problem.

One other point: I see you are adding the grid columns dynamically, using code like THISFORM.grid1.ADDOBJECT(). Whenever I add an object in that way, I always remove it, using something like THISFORM.grid1.RELEASEOBJECT(). I would do that before releasing the form. I don't know whether it would help with your problem, but it might be worth a try.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top