Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can you have Singleton objects in VFP?
Message
De
09/07/2003 11:25:17
 
 
À
09/07/2003 09:57:03
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Divers
Thread ID:
00808442
Message ID:
00808519
Vues:
19
>Yes, I was thinking of having a class that could return references to it's own instances of the required classes.
>
>Thanks
>
>Kev
>
>>I doubt you can do it the normal way. Load and Init are events, not methods. You'd have to have whatever class is creating the object first check to see if it already exists and then instantiate it or not as required. It could be as simple as checking "Type('MyObject.Name') = 'C'
>>
>>I suppose you might do it in the Load, but I think it would be simple to do it before.
>>
>>Alan
>>
>>>Hi
>>>
>>>Is this possible from VFP?
>>>
>>>Thanks
>>>Kev


Sorry the last message is incomplete, this is the complete.

>Hi
>
>Is this possible from VFP?
>
>Thanks
>Kev

Is the most near I´m from a Singleton Pattern in VFP ;-D
*-- Init Method - pseudo-Singleton
*--
LPARAMETER loMyObject 
loMyObject = .NULL.

loMyObject = THIS.IAmAlone()

IF ISNULL(loMyObject)
  *-- I´m the first and the unique ... I think...

ELSE
  RETURN .F.
ENDIF

*-- IAMAlone Method()
*--
LOCAL loReturn
loReturn = .NULL.

LOCAL ARRAY aClassInst[1]
DIMENSION aClassInst[1]

LOCAL lcClassSeft, lnClassInst 
lcClassSeft = this.Class 		
lnClassInst = 0				

lnClassInst = AINSTANCE(aClassInst, lcClassSeft)

IF lnClassInst > 0
	loReturn = aClassInst[1]
ENDIF

RETURN loReturn
This code no assure a unique instance, but is the most I can do.

Regards,
José Luis.

Quidquid latine dictum sit, altum sonatur

Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform