Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Classes - Best Practices?
Message
 
À
12/03/2003 18:17:37
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00763778
Message ID:
00765247
Vues:
20
John -

I'm with Steve on this one. After years of putting non-visual classes into VCX files, I've returned to using PRG files to define most of these classes in. The benefits:

- Much easier to read through the code

- Easier to use #include and #define constants
I never liked the global include feature available for VCX files, as you can only define one without nesting them. Therefore, I had resorted to using #include in each individual method.

- NewObject() method makes it very simple to create instances

- I don't use the Class Browser much, so that's not an issue. The VFP 8 Toolbox is good at rendering classes that are in PRG files.

>John,
>
>>
>>If I put each class in a separate .PRG file I need to use a sequence of SET PROCEDURE TO ... ADDITIVE commands to use them within my apps and they won't show up in the class browser at all - at least not that I've seen.
>>
>
>You can use SET PROCEDURE TO, or you can use newobject() to tell it where to find the class definition.
>
>oInstance = newobject("class1","class1.prg")
>
>
>>However, if I put them all in a VCX file I get the benefit of them showing in the class browser and being able to add them all with one SET CLASSLIB TO... command. While I would prefer having everything in code, it looks like I basically have to fight VFP to do it. So I'm leaning toward the VCX files for ease of use - even though my classes are not visual.
>>
>
>I prefer .prg files for non-visual classes, using newobject() to create objects.
>
>>So I have another question...
>< snip >
>Is there a way in a visual class to use #DEFINE to create a constant that is available to any method in the class? For that matter, can you create a non-public variable that is available to any method in the class? It doesn't appear that it's possible from what I've tried so far. A constant declared in the Init event does not appear to be available to a user-defined method. And variables only seem to be available if created as PUBLICs.
>>
>>With the .PRG approach, I can create constants at the beginning of a class definition and #UNDEFINE them afterwards and have, in effect, a class level constant. I don't think I can do the same with variables as any variables declared at the class level become properties.
>>
>>Any thoughts?
>
>What is wrong with using properties of the class? Look at HIDDEN and PROTECTED keywords in DEFINE CLASS command, maybe that will help you get the scope you desire...
>
>My ideas are worth about $.02US. :)
Ryan Katri
COB System Designs, Inc.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform