Dear sir,
Like khurram, i was also using formsets and for the last 3 months have stopped using. This explanation was really helpful.
Thanks
> Khurram
>
> > Thanks for your illustration on this topic can you further guide me about following Q1. how i made a common DataEnvironment ?
> > Q2. What is DE
> > Q3. How to set all forms to use default datasession.
>
> Forms have two settings for their DataSession Property - the first (Default) means that when a form is instantiated it sets itself to whatever data session is current at that time. The second (Private) means that the form creates its own datasession.
>
> So this means that if you create a form that uses a Private DataSession, and add tables to its DataEnvironment (=DE), and set the DE's AutoOpenTables and AutoCloseTables properties, then when the form runs, it will open those tables and when the form is closed, it will close those table.
>
> Now if your form calls another form (using DO FORM command) and the child form has its DataSession Property set to DEFAULT, then it will open up in the same datasession as the first form, and so it can access the same tables, use the same record pointers and in short, behaves just like a pair of forms inside a formset!
>
> Is that clear?
>
> Now, if you need to get a reference, in the child form to the form that called it, you can do that in the LOAD() event because, when a form is initializing, the VFP _Screen.ActiveForm property is still pointing to the form which is currently active (i.e. the Parent Form). So just use code like this in a child form to get a reference to its parent (this can even go into your "childform" class and you never have to worry about it again!):
>
>
IF TYPE( "_Screen.ActiveForm" ) = "O" AND NOT ISNULL( _Screen.ActiveForm )
> ThisForm.AddProperty( "oParentForm", _Screen.ActiveForm )
> ELSE
> ThisForm.AddProperty( "oParentForm", NULL )
> ENDIF
> (Note: This code ensures that if a form is called, say from a menu, and there is no other form active it will not crash)
>
> Note also that even if a form has a private datasession, you can easily switch it to use a different datasession just by setting its DataSessionID property - although if you have bound controls on such a form you had better make sure that the datasession you are changing into has the correct tables open or you will get errors. So to switch a child form into the parent form's datasession you just use the reference generated above and add this line of code to the form's LOAD too....
>
>
ThisForm.DataSessionID = ThisForm.oParent.DataSessionID
>
> You can even handle toolbars in a similar way (they are a special type of form class, and also have a DataSessionID property).
>
> So as you can see, you can share data environments, refer to other forms and, in short, do everything that you can do in a formset, without needing to use one, and without all the problems that formsets cause.
>
> Regards
> Andy Kramek
> Microsoft MVP (Visual FoxPro)
>
Tightline Computers Inc, Akron Ohio, USA