Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can a class see what it's instantiated as?
Message
De
09/10/2015 16:36:01
 
 
À
09/10/2015 16:09:38
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01625748
Message ID:
01625794
Vues:
49
>>I have a moment of brain shortage, right now I can't see the forest for all the trees. Is it possible from within an object to know what is the name it's instantiated as? Given this code
>>
>>
>>loCountries = NewObject('SqlTable','SQL.vcx')
>>
>>In this case I want the class SqlTable to understand that it's instantiated as loCountries. I am building a rather complicated generic class to work with SQL tables. My idea is that if I call the object for instance loCountries, my class can be smart enough to know that I want it to connect to the SQL table called Countries.
>
>I'd be inclined to pass in parameter(s):
>
>loCountries = NewObject('SqlTable','SQL.vcx', 'Countries', MyParam2, ... )
>
>Or has already been suggested, set an object property after it's created.
>
>In your sample code you may be working on a concrete method using Countries, so you want to use loCountries. But if in fact it's generic and you are generating the variable name, then there probably already is a parameter or property used to generate the variable name, so you could just pass that to the SQL object.
>
>Something like that is likely to be simpler to maintain and more robust than deriving the variable name.

I decided to set a property which holds the name of the table. This makes more sense, since for some of the tables, especially for lookup, I create subclasses where the table name is set in the subclass. I also have a property for the database name since I don't store all the tables in one database. Sometimes you realize that what seemed like a good idea, wasn't so good after all.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform