Since a GRID or perhaps a Combo may be refreshed
anytime, using SET DATASESSION TO is risky, whether you set it back or not. Why not just let VFP do all this natively? Create a session object. Ask it to create anything you desire.
This.oProperty = NEWOBJECT("SessionThing", "PRG.PRG")
This.PrivateDSObject = This.oProperty.Create("Anything", "ClassLibOrPRG")
Now I never worry about SET DATASESSION TO at all. Just send messages to the This.PrivateDSObject. This assumes you add a Create procedure to your SessionBase class, which isn't very hard.
>>Hi Doru,
>>
>>Actually, your question helped me also. Today I tried the same approach as you did and I found, that changing DS in a program lead to form Grids loosing their RecordSource. If I use class (not a program), I don't encounter this problem. Therefore I switched to class.
>
>If a class works for you, that's great. But if you ever do switch datasessions in code, the best bet is to put it back to where you found it when you're done, before you return from your code.
Charlie