Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How can I prevent a class from changing datasession?
Message
De
12/06/2002 20:46:03
 
 
À
08/06/2002 14:39:30
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00666267
Message ID:
00667746
Vues:
23
>>>I created a custom class, and sub-classed it for each table in my database.
>>>I createobject() in dbc_AfterOpenTable(cTableName). I put all my data validation routines into it, but sometimes when one of the methods starts, it switches datasessions and can't find the table. I think I reached the conclusion that it switches to whatever datasession it was created in. And whenever I try to use it from a different datasession, it crashes.
>>>
>>>TIA
>>
>>That's the way classes work, they inherit the datasession they're created in. If you need your class to work in a specific datasession, create that class in that datasession, or pass the datasessionid to your class as a parameter. Just be sure to set it back to whatever it was before you return from your class.
>
>Hi Fred,
>
>I kinda figured that out the hard way.
>But do I HAVE to set it back to whatever it was before returning? Wouldn't the class that I was in before automatically set it back?

No, I don't think so, at least that's been my experience that it's best to do your own housekeeping (if you change it, put it back where you found it). The particular problems I've seen are dangling datasessions leading to forms that won't close, and C...5 errors if you don't clean up.

I would think that a class is only capable of changing to it's datasession on the original entry to the class, not on return from some other class, but I could be wrong. I don't know how their mechanism works exactly.


>
>public goC1
>goC1 = createObject('c1')                      && datasession 1
>
>do form whatever                               && datasession 2
>  whatever.method()
>    goC1.SomeThing(set('DataSession'))
>    .....                     <<<<<<<<<<< would datasession AUTOMATICALLY change back to 2 here?
>  endmethod
>endform
>
>define class c1 as custom
>  procedure SomeThing(nDataSession)

     LOCAL nCurrentDS
     nCurrentDS = SET("DataSession")

>    set datasession to nDataSession
>    .....

     SET DATASESSION TO nCurrentDS

>  endproc
>enddefine
>
Fred
Microsoft Visual FoxPro MVP

foxcentral.net
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform