Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Q: read-only property, the shortest implementation?
Message
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00927230
Message ID:
00927498
Views:
20
Anatoliy,

>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:

Here's what I think is the way to do this.
obj = CreateObject("myclass")
? obj.GetHWindow()
? obj.SetHWindow
* obj.hwindow = 0  && generates an error
* end of main

DEFINE CLASS myclass As Custom
  HIDDEN HWindow
  HWindow = 0

  PROCEDURE Init
    This.SetHWindow
    RETURN
  ENDPROC

  FUNCTION GetHWindow

    RETURN This.HWindow
  ENDFUNC

  PROCEDURE SetHWindow
    DECLARE INTEGER GetFocus IN user32
    
    This.HWindow = GetFocus()
    RETURN
  ENDPROC
ENDDEFINE
How's that?
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform