Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Q: read-only property, the shortest implementation?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Titre:
Q: read-only property, the shortest implementation?
Divers
Thread ID:
00927230
Message ID:
00927230
Vues:
84
In FoxPro class I want to create read-only property. Its value can be changed by internal method(s) of the class, but can not be changed by direct assignment when an object is instantiated from this class.

So far the best I can do is combination of protected "shadow" property and ASSIGN method for the base property. The code is very abstract, just an example of general idea:
obj = CreateObject("myclass")
? obj.hwindow
* obj.hwindow=0  && generates an error
* end of main

DEFINE CLASS myclass As Custom
PROTECTED _hwindow
	hwindow=0

PROCEDURE Init
	THIS.GetHWindow

PROCEDURE hwindow_ASSIGN(newvalue)
	ERROR 1740, "HWindow"
	
PROCEDURE hwindow_ACCESS
RETURN THIS._hwindow

PROTECTED PROCEDURE GetHWindow
	DECLARE INTEGER GetFocus IN user32
	THIS._hwindow=GetFocus()

ENDDEFINE
Is there a better way? Somehow this triple-member does not look Ok.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform