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 14:52:27
 
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:
01625784
Vues:
62
>>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.
>*
>You may have given up on the idea, but, if I understand it correctly, and just for the fun of it:
>
>
>***==================================
>DEFINE CLASS yourClass AS Custom
>***==================================
>	** Which would include this method as a member
>	
>	***************************
>	FUNCTION WhatVarAmIKnownAs
>	***************************
>	LOCAL i, lcRet, loi
>	LOCAL ARRAY aI[1]
>	*
>	lcRet = ""
>	*
>	AINSTANCE(aI, This.Class)
>	*
>	FOR i = 1 TO ALEN(aI)
>		loi = EVALUATE("m." + aI[m.i])
>		IF m.loi = This
>			lcRet = aI[m.i]
>			EXIT
>		ENDIF
>	ENDFOR
>	RETURN (m.lcRet)
>
>ENDDEFINE
>
Nice, it works just fine. However, I realized that it wasn't a good idea after all.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform