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
Divers
Thread ID:
00927230
Message ID:
00927247
Vues:
30
>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.

Change:
PROTECTED _hwindow
to:
HIDDEN _hwindow
To prevent access and changes to the properties from outside of the class definition. Only methods and events within the class definition can access the hidden properties. While protected properties can be accessed by subclasses of the class definition, hidden properties can only be accessed from within the class definition.

Hope this helps,
Dawa Tsering


"Do not let any unwholesome talk come out of your mouths,
but only what is helpful for building others up according to their needs,
that it may benefit those who listen."

- Ephesians 4:29-30 NIV

Dare to Question -- Care to Answer

Time is like water in a sponge, as long as you are willing you can always squeeze some.

--Lu Xun, Father of Modern Chinese Literature

Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform