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

PageFrame and Multiple DataSessions, 1 for each tab

Status
Not open for further replies.

Goofus828

Programmer
Nov 9, 2005
127
US
Hi all
I have a 10 tab page-frame and I would like to have 10 separate data-sessions. This is for ease of use because I have so many tables open but each tab does not use them. I just would like to open the tables that are used in each tab so the filters, pointer and relationships do not cross over tabs.
The Form’s Data-session is 2 – Private Data Sessions
In the LOAD of my form I create 10 data-session, 1 for each tab called TabSession1, Tabsession2 and so on.
The datasessions are created this way:
Code:
FOR i = 1 TO 10
	cTab = "TabSession" + ALLTRIM( STR( i ) )
	&cTab. = CREATEOBJECT("Session")
	cTab = cTab + ".Name"
	cName = "Tabsession" + ALLTRIM( STR( i ) )
	cTab = cTab + " = 'Tabsession" + ALLTRIM( STR( i ) ) + "'"
	&cTab.
        Set datasession to i
        Do Case
            Case I = 1
	    *Open tables for this tab in data session “I”
	    Case I = 2
	    ...	    
	EndCase
Endfor

This works fine. Ten new sessions are created with the tables I want for each tab.
The problem is when the INIT of the objects on each tab are executed; errors are generated – specifically on the Grids.

Here is the Error:
Error Number: 2005
Message : Error loading file - record number 14. _grd_Search <or one of its members>. ControlSource : Alias 'MASTEXEM' is not found
.
MastExem is open in DataSession 1 which correlates to Tab1.


I am thinking that at the INIT execution, VFP does not know about the multiple datasessions and it is ‘stuck’ on the default datasession.
Is there a solution/way around this?


 
Take a close look, the datasession property of the form says 2 – Private Data Session, not Datasessions.
A form is not designed to have multiple datasessions. The form and all controls on it are bound to the same datasession.
Any object created (except Session objects) is kind of bound to the session that was running, when it was created, ecept the ones, that are child objects, like Pages. They are always created in the same datasession as the parent object. And what you also can't do is create a page object into a variable via oPage = CreateObject("myPage") and add that to the pageframe.

Your concept will not work. Rather use Aliasnames and AGAIN clause, that's your only option.

I'll not go into details, but even if your concept would work one major error you do is: Set datasession to i, think about it.

To show you the effect of objects created in datasessions, execute this:
Code:
_Screen.RemoveObject("pgf")
_Screen.AddObject("pgf","mypageframe")

With _Screen.pgf
   .MemberClassLibrary = Forceext(Sys(16),"prg")
   .MemberClass = "mypage"

   Clear
   ? "screen datasession:", _screen.DataSessionId
   oS1 = Createobject("Session")
   ? "   oS1 datasession:", oS1.DataSessionId
   Set DataSession To oS1.DataSessionId
   .PageCount = .PageCount + 1
   oS2 = Createobject("Session")
   ? "   oS2 datasession:", oS2.DataSessionId
   Set DataSession To oS2.DataSessionId
   .AddObject("Page2","mypage")
   oS3 = Createobject("Session")
   ? "   oS3 datasession:", oS3.DataSessionId
   Set DataSession To oS3.DataSessionId
   oP1 = Createobject("mypage")

   .Visible = .T.
   Activate Screen
   ?
   ? "pageframe datasession", .getsession()
   ? "    page1 datasession", .Pages(1).getsession()
   ? "    page2 datasession", .Pages(2).getsession()
   ? "      oP1 datasession", oP1.getsession()
Endwith

Define Class mypage As Page
   Caption = "mypage"
   Procedure getsession
      Return Set("datasession")
   Endproc
Enddefine

Define Class mypageframe As PageFrame
   PageCount = 0
   Top = 200
   Procedure getsession
      Return Set("datasession")
   Endproc
Enddefine

This shows you, only the page created into the variable oP1 is in a private new datasession, but it's not part of the pageframe, and you can't add the object to that pageframe. The other two pages you can see are generated in the two possible ways there are, via incrementing pagecount and via addobject, both are created in the same datasession as the pageframe.

There is no way to show the oP1 page, you can create a control into a variable, but it can only be made visible inside a form, A variable is no form.

Your idea does not work out, all controls will need their datasources in the same datasession as the form is in.

Bye, Olaf.
 
Pardon this: I forgot to remove the first line, it was needed to make multiple test runs, but in the first run this will of course error, as there is not yet such an object of _screen.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top