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:
00927265
Vues:
23
This message has been marked as a message which has helped to the initial question of the thread.
Hi Anatoliy,

Here's another way
DEFINE CLASS myclass As Custom
HIDDEN lInternalAssigment
hwindow=0

PROCEDURE Init
	THIS.GetHWindow()

PROCEDURE hwindow_ASSIGN(newvalue)
	IF This.lInternalAssigment
		THIS.hwindow = newvalue
	ELSE
		ERROR 1740, "HWindow"
	ENDIF	

PROCEDURE hwindow_ACCESS
RETURN THIS.hwindow

PROTECTED PROCEDURE GetHWindow
	DECLARE INTEGER GetFocus IN user32
	This.lInternalAssigment = .T.
	THIS.hwindow=GetFocus()
	This.lInternalAssigment = .F.
ENDDEFINE
>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.
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform