Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
The Session object and Grids
Message
De
21/02/2009 11:22:32
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Divers
Thread ID:
01380409
Message ID:
01383272
Vues:
59
>>>Is there any way to use the session object harmoniously with grids? I wrote a control that's based on a container. It creates a Session object and opens all it's data inside the session. Within any of the controls methods that needs access to the controls data I switch the DataSession to point to the controls Session, do whatever I need to do, and then reset the datasession to the default. The reason this is important is that there may be any number of these controls on a form and they all need to have a private copy of the data.
>>>
>>>This works great, but... When I put the control on a form that contains a grid, every time I switch the datasession within my control the grid looses its RecordSource. This is understandable since the grids RecordSource is going out of scope, but, it's a real dissapointment because it makes the session object, at least for my purposes, useless. I can't believe that there isn't a way around this problem... How do you give a user defined VFP control it's own DataSession without perturbing the other controls in your system?
>>>
>>>It seems so simple. There should be a way to reference your data based on the datasession the cursor resides in. Something like:
>>>
>>>oDataSession1.MyTable.TableField1
>>>
>>>Any ideas?
>>>
>>>Thanks,
>>>
>>>Steve
>>
>>VFP cannot split a form into two or more datasessions.
>>
>>When you set the datasession into one form's method ( at any level ) the whole form go into that datasession.
>
>Thanks a lot. In other words, we can instantiate a session based class and do processing it it, but we can not do using SET DATESESSION ID.
>

this is a simple example where you can see the VFP datasession logic:
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show

DEFINE CLASS form1 AS form


	DataSession = 2
	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"


	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 12, ;
		Left = 12, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "Form win", ;
		Name = "Command1"


	ADD OBJECT container1 AS container WITH ;
		Top = 60, ;
		Left = 12, ;
		Width = 156, ;
		Height = 84, ;
		Name = "Container1"


	ADD OBJECT command2 AS commandbutton WITH ;
		Top = 12, ;
		Left = 180, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "Session win", ;
		Enabled = .F., ;
		Name = "Command2"


	ADD OBJECT container2 AS container WITH ;
		Top = 60, ;
		Left = 180, ;
		Width = 156, ;
		Height = 84, ;
		Name = "Container2"


	PROCEDURE command1.Click
		MESSAGEBOX("form.datasession"+STR(thisform.DataSessionId))

                * whit addobject the session doesn't create a new datasession
		THISFORM.Container1.AddObject("osession","Session")
		MESSAGEBOX("form.datasession"+STR(thisform.DataSessionId);
				+	CHR(13) +	"Container1.osession.datasession"+STR(THISFORM.Container1.osession.DataSessionId))

		thisform.Command2.Enabled = .T.
	ENDPROC


	PROCEDURE command2.Click
		MESSAGEBOX("before form.datasession"+STR(thisform.DataSessionId))
		formDatasession = thisform.DataSessionId
		WITH CREATEOBJECT("Session")
			SET DATASESSION TO .DataSessionId
			MESSAGEBOX("after form.datasession"+STR(thisform.DataSessionId);
				+	CHR(13) +	"Container1.osession.datasession"+STR(THISFORM.Container1.osession.DataSessionId))
			ASESSIONS(ass)
			MESSAGEBOX("exists the before form.datasession ? "+TRANSFORM(not EMPTY(ASCAN(ass,thisform.DataSessionId))))
		ENDWITH
	ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************
the VFP is a structural design, it is not a Form's design

this is the same example with a not visual container:
WITH CREATEOBJECT("session")
	SET DATASESSION TO .DatasessionId
	NEWOBJECT("Container1")
ENDWITH

DEFINE CLASS Container1 AS Container

	DataSessionId = NULL

	PROCEDURE init
		
		MESSAGEBOX("container.datasession"+STR(this.DataSessionId))
		THIS.AddObject("osession","Session")
		MESSAGEBOX("container.datasession"+STR(this.DataSessionId);
				+	CHR(13) +	"container.osession.datasession"+STR(THIS.osession.DataSessionId))

		* now change the container datasession
	
	
		WITH CREATEOBJECT("Session")
			SET DATASESSION TO .DataSessionId
			MESSAGEBOX("container.datasession"+STR(this.DataSessionId);
				+	CHR(13) +	"container.osession.datasession"+STR(THIS.osession.DataSessionId))
		ENDWITH
	ENDPROC

	
	PROCEDURE DataSessionId_Access
		RETURN SET("Datasession")
	ENDPROC

ENDDEFINE
>Or may be there is a way to temporarily unbind all controls?

No. Every VFP object it is bind to a datasession ( except VFP bugs ),
ie SET("Datasession") always returns a datasession.

You can only change the object's datasessionId of any _VFP.object item!
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform