Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to prevent datasession switching on global object ca
Message
De
11/07/2005 20:09:05
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
 
À
11/07/2005 08:44:21
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Versions des environnements
Visual FoxPro:
VFP 7
Database:
Visual FoxPro
Divers
Thread ID:
01031168
Message ID:
01031440
Vues:
16
>I created global object g_server in default data session based on custom class.
>
>I call this object methods from prg files.
>I want that methods are executed in the caller datasession.
>However, FoxPro switches datasession to the session where g_server is created on call.
>
>I cannot pass datasession id as parameter since it is difficult to determine the datasession id (prg nesting is deep, this requires major re-write).
>
>Using
>
>SET DATASESSION TO (thisform.DataSessionId)
>
>causes error object is not contianed in form
>
>Using
>
>SET DATASESSION TO (_screen.activeform.DataSessionId)
>
>causes sometimes error _screen.activeform is not an object
>
>
>How to disable datasession switching when calling global object method ?


Only two ways about it:

- create a private instance of this object, as a member of your form. As long as it's created within the form, it will share the form's datasession ID.

- pass the current datasession ID as a parameter, or pass the form itself. This technique is commonly used in various frameworks, specially those that handle SPT.

Any object lives in the datasession in which it was created, i.e. its code switches the datasession when it executes. For global objects, this is DS 1. Since your form usually has a DS of 2, 3 etc - either pass the form or the DS ID.

Note: _screen.activeform may be null if the focus is somewhere else - you may be executing toolbar code, menu code, report code, OKL code (didn't really play much with these), or are between a deactivate of one thing and the activate of the next. That's why I either make sure the object that needs to be addressed has passed itself as a parameter, or that I really check whether _screen.activeform is null. Can't trust it, really.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform