Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Classes - Best Practices?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00763778
Message ID:
00765375
Vues:
20
John,

>Well, nothing actually except that you have to UNDEFINE them at the end of a method/procedure if you want them to be local in scope - unless I'm misunderstanding something. In VB, constants created within a method/function/sub are local unless declared as public. Perhaps "approximate" was a bad choice of words.

Why do you really need to UNDEFINE them? What sort of local constants are you trying to create that you want only scoped to a method and not to the whole class?

If you want method scoped #DEFINEs you can do a #DEFINE in the method or simply #INCLUDE the .h file in that method then no other methods see the #DEFINEs. The only reason to use a .h would be so that you can have the same #DEFINEs available to another method. I think that would lead to a plethora of .h files though. Again a little context of what you are doing will help us give you some options on the ways to do it in VFP.

>Okay, that hadn't occurred to me. That should handle the class-level constants that I need. But is the scope of those constants such that they are only available to the class or do they become available to all the classes within a library?

They are available to all methods of that class. They are also available to anthing that #INCLUDES them, so other visual classes or PRGs or Forms can have access to them with a simple #INCLUDE (or menu selection include).

Since classes in classlibs and forms only allow one include file you are a bit constrained when it comes to the inheritance of #DEFINEs. The way I chose to work under this situation was every classlib has a .H, any #DEFINES needed for all classes in the classlib are put into that one file. If a class needs to use #DEFINEs it simply does the include for its own classlib. Now say I subclass something from ClassLibA into a new ClassLibB, the subclass in theory, and practice, needs access to the #DEFINEs of the parent class right? This can be accomplished by making ClassLibB.h:
#include ClassLibA.h
* additional #defines for classes in ClassLibB follow
#define blah blah
If a form needs to use the #DEFINEs of any of the classes in it then I create a FormName.h and do all of the necessary #INCLUDEs for the classlib.h files.

Working under this structure really makes it easy for me to have the right sorts of access to the #DEFINEs I've set up.
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform