Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Object not available in procedure
Message
 
À
14/05/2008 08:13:33
Jay Johengen
Altamahaw-Ossipee, Caroline du Nord, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Divers
Thread ID:
01316922
Message ID:
01316924
Vues:
13
This message has been marked as the solution to the initial question of the thread.
>I have a PRG that the object goes out of scope when a procedure is called. Do I need to pass it in somehow?
>
>
>LOCAL myObject
>
>MyObject = CREATEOBJECT("MyClass")
>
>DO MyProcedure
>
>RETURN
>
>PROCEDURE MyProcedure
>
>   * MyObject is not available
>
Yes. Because you declare myObject as LOCAL it is visible only in routine where it is declared. So you have two choices:

1. Declare it PRIVATE:
PRIVATE myObject
MyObject = CREATEOBJECT("MyClass")

DO MyProcedure
RETURN


PROCEDURE MyProcedure

   * MyObject is available now
or pass it as parameter:
LOCAL myObject

MyObject = CREATEOBJECT("MyClass")

DO MyProcedure WITH MyObject

RETURN

PROCEDURE MyProcedure(MyObject)

  * MyObject is available
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform