Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Variable Scoping
Message
De
23/12/2003 17:58:02
 
 
À
23/12/2003 16:46:46
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Divers
Thread ID:
00861687
Message ID:
00861792
Vues:
31
Fred, have you looked at the example I posted? The only 'sin' committed by the code that got a global by reference was to cause an implicit refresh of current relations by calling SET DATE, yet this caused a completely different, unrelated subsystem - symbolized by the RELA_() function - to break since the global was no longer visible (type([m.g_uTest]) == 'U').

In some cases the problem can be avoided by rewriting the interface from
function ModifyFoo (roFoo)
   * ...
   roFoo = m.oNewFoo
   return <whatever>

* elsewhere ...
if ModifyFoo(@m.g_oFoo) == <whatever>
   * ...
endif
to
function ModifyFoo (oFoo, ruStatus)
   * ...
   ruStatus = <whatever>
   return m.oNewFoo

* elsewhere ...
local uStatus
g_oFoo = ModifyFoo(m.g_oFoo, @m.uStatus)
if m.uStatus == <whatever>
   * ...
endif
But this means that the ModifyFoo() call can no longer participate in things like CASE statements and other conditionals unless a wrapper is written:
function ModifyGlobalFoo
   local uStatus
   g_oFoo = ModifyFoo(m.g_oFoo, @m.uStatus)
   return m.uStatus

if ModifyGlobalFoo() == <whatever>
   * ...
endif
Bottomline: the ModifyFoo() code has to be changed even though it does not deal with any globals directly, and the code that calls ModifyFoo() has to be changed one way or another. And the whole shebang just got a bit messier instead of leaner/meaner/cleaner during maintenance. ;-)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform