Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Objects getting clobbered - scope problem?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00913041
Message ID:
00913064
Vues:
15
It looks like in my simple testing based upon your example, declaring the object LOCAL within the called function seems to work as expected, avoiding the conflict. I'll have to look more carefully at my production code to make sure I declared as local all the objects within functions.

Thanks to both of you for the response.

>Hi Michel,
>
>I don't see this in my test. What I'm doing differently? Running VFP8SP1.
oRec = Null
>=f1()
>RETURN
>
>FUNCTION f1
>*LOCAL oRec
>CREATE CURSOR testxx1 (ii1 int, cc1 char(2))
>INSERT INTO testxx1  VALUES(1, "#1")
>SCATTER NAME oRec
>? oRec.ii1, oRec.cc1
>=f2()
>? oRec.ii1, oRec.cc1     && oRec object wasn't changed after call to f2()
>RETURN
>
>FUNCTION f2
>LOCAL oRec
>CREATE CURSOR testxx2 (ii1 int, cc1 char(2))
>INSERT INTO testxx2  VALUES(2, "#2")
>SCATTER NAME oRec
>RETURN
>
>>I have an application which creates an object (SCATTER NAME) which then calls a function which happens to create an object by the same name. The function destroys the object before returning.
>>
>>I was expecting that by defining the object as LOCAL or PRIVATE within the function, it would not clobber the identically named object in the calling function. I appear to be wrong because the object in the calling program is getting clobbered by the one in the function.
>>
>>Either I'm not understanding how to properly scope the object in the calling and called function, or objects behave differently than other variables.
>>
>>Can someone shed light?
>>
>>TIA
Kogo Michael Hogan

"Pinky, are you pondering what I'm pondering?"
I think so Brain, but "Snowball for Windows"?

Ideate Web Site
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform