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

Keep Losing Data Environment

Status
Not open for further replies.

fmoore0001

Programmer
Dec 3, 2002
192
US
Guys, I have a form where the data environment is set in the form modeless), but when I move to another (modal) form the data environment appears to disappear?

Checking the status of the open tables, ALIAS() reports no table open, yet moving back to the form and the form can perform Next, Previous, Top, Bottom with no problem

The odd thing is that this was working a short time ago. What the heck could I have changed?

Frank
 
Frank,

At first glance, it sounds like the forms have different data sessions. Check the data session property of both forms. You probably want to set it to 1 - Default, especially for the modal form.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
The funny thing is that I cannot find any as to the behavior of these forms.

1) When I bring up any PRIMARY TABLE form up it has a data environment set. The opening of the form is supposed to opens the tables, and closing closes the tables. The forms are all modeless;

2) I have no trouble doing Next, Previous, Top, Bottom, etc. movements in the table records;

3) I have a universal Find form that responds to the f5 key for finding with a grid display of records. It is modal, with opening tables and closing tables set to .F. as it is presuming that the tables are open from the PRIMARY TABLE form. Now, as soon as the FIND FORM comes up the command ALIAS() shows no table open, yet DBF() shows the correct table name;

4) i build the grid based on the field columns and table. Even though I show the table open, the grid screen sometimes does not get through the opening process.

Any other ideas> Thanks!

Frank
 
Frank,

As MikeLewis intimated, are you quite sure that your find form has its Datasession property set to "1 - Default" when you look at it in the properties window during design?

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
This is indeed driving me nuts, now. The PRIMARY (modeless) form is set to a private data session with a data environment all set. It opens and connects the tables without problem. Next and Previous displays show appropriate movement in all tables.

Yet, when I move to another form from the PRIMARY form, a modal form set to the DEFAULT environment, the data environment of the PRIMARY form seems to disappear. I even have to do a USED test to see if the primary TABLE is opened (it is not) and open it. Of course, I have lost my connection (child) tables too.

Why does the data environment, even to the point of the open tables, disappear when I open the modal form. This should not happen.

Frank
 
Frank,

Are you launching the modal form from the modeless form? If so, and if the modal form has a default data environment, it will "inherit" the data environment from the modeless form ("default" is a bit mis-leading; it doesn't mean the public de, but rather the de that was current when the form was created).

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Mike, here is the wierd part. You said:

Are you launching the modal form from the modeless form? If so, and if the modal form has a default data environment, it will "inherit" the data environment from the modeless form.

That is exactly what I thought. Yet, I can verify that as soon as I leave the Modeless, working form, and start the modal form with the default data environment, I cannot see it any longer and literally have to open the tables again. It is blowing my mind. It is like the behavior of a LOCAL variable.

Frank
 
fmoore0001,

Can you run the following and let me know if it is acts as expected for you:
Code:
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
READ events

DEFINE CLASS form1 AS form
	Top = 0
	Left = 0
	Height = 147
	Width = 301
	DoCreate = .T.
	Caption = "MODELESS"
	Name = "Form1"
	Autocenter = .T.
	WindowType = 0 &&Modeless
		
	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 24, ;
		Left = 24, ;
		Height = 27, ;
		Width = 252, ;
		Caption = "Open Form Using DEFAULT Datasession", ;
		Name = "Command1"
		
	ADD OBJECT command2 AS commandbutton WITH ;
		Top = 84, ;
		Left = 24, ;
		Height = 27, ;
		Width = 252, ;
		Caption = "Open Form Using PRIVATE Datasession", ;
		Name = "Command2"
		
	PROCEDURE Load
		CREATE CURSOR crsTest (somefld c(30))
		INSERT INTO crsTest (somefld) VALUES ("HELLO WORLD")
		INSERT INTO crsTest (somefld) VALUES ("GOODBYE MARS!")
	ENDPROC
	
	PROCEDURE command1.click
		LOCAL oForm
		oForm = CREATEOBJECT("form2")
		oForm.show()
	ENDPROC
	
	PROCEDURE command2.click
		LOCAL oForm
		oForm = CREATEOBJECT("form3")
		oForm.show()
	ENDPROC
ENDDEFINE

DEFINE CLASS form2 AS form
	Top = 0
	Left = 0
	Height = 140
	Width = 300
	DoCreate = .T.
	Caption = "DEFAULT DATASESSION"
	Name = "Form2"
	AUTOCENTER = .T.
	Datasession = 1 &&Default 
	WindowType = 1 &&Modal
	
	PROCEDURE Activate
		IF USED("crsTest")
			MESSAGEBOX("I can see it:" + crsTest.somefld,64,"CAN SEE CRSTEST")
		ELSE
			MESSAGEBOX("crsTest is hidden from me!",16,"I CAN'T SEE CRSTEST")
		ENDIF
	ENDPROC
ENDDEFINE

DEFINE CLASS form3 AS form
	Top = 0
	Left = 0
	Height = 140
	Width = 300
	DoCreate = .T.
	Caption = "PRIVATE DATASESSION"
	Name = "Form3"
	AUTOCENTER = .T.
	Datasession = 2 &&Private 
	WindowType = 1 &&Modal
	
	PROCEDURE Activate
		IF USED("crsTest")
			MESSAGEBOX(crsTest.somefld,64,"CAN SEE CRSTEST")
		ELSE
			MESSAGEBOX("crsTest is hidden from me!",16,"I CAN'T SEE CRSTEST")
		ENDIF
	ENDPROC
ENDDEFINE

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Thank you for the big test. Mine reports:

Default Data Session: Can See it.

Private Data Session: Cannot See it.

Was this supposed to happen?

Frank
 
Yes, the most important part of that was that the modal form with the default datasession you bring up that says it "can see it" means that the form can see the cursor that was created in the modeless form. So something else is going on with your problem since the modal form with a default datasession operates as expected. Now we just need to figure out why your your datasession appears to change when you go to that modal form you've got. It should operate the same way as this test did and you should be able to see all of the tables you opened up in the Modeless form from your Modal form with the datasession set to default for it. Same principal as the code I had you test. So either there is some code changing datasessions on you or there is corruption somewhere. The test I had you run doesn't really give you that answer specifically but it does show that your VFP environment is operating and behaving as expected with respect to Default and Private datasessions.

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
The answer to the problem your is simple, when you use the private data session it means that you want to hide all the tables you open for that form from the another form. for example you a form ('myform1') that has the datasession set to private you can open a table and work with it just fine, but if you lunch another form ('myform2'), all the tables that are open on ('myform1') are not available on ('myform2')

hope it solve your problem.
 
twofear,

That's not entirely accurate...if I have a form (form1) with a private datasession and launch another form (form2) from form1 and form2 has it's datasession set to Default then I am in the same datasession (created by form1) and can see and use all of the tables opened in that datasession. See further explanations in:

what is PRIVATE DATA SESSION
thread184-773272

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top