Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Public/Protected /Hidden
Message
From
03/08/2000 14:14:55
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00398708
Message ID:
00400556
Views:
32
Gerard:

> If you cannot access a protected property in an instance of the class, what
> is the purpose of 'protecting' the property.

I normally create protected (or hidden) properties to protect an internal (to
the class) read-write property against possible bad assignments at the form
level (subclass level if hidden).

I almost inevariably create some protected methods to manipulate these
properties and I may, but not always, create public GetXXX methods to access
these properties on a form.

For example, I have some special controls that self-register at runtime on
the form on which they are instantiested. The form CLASS has protected
Register() and Unregister() methods (I don't want the other developers to
change these mechanisms) protected RegisteredControlCount and
RegisteredControls[1,0] roperties. The form also has public
GetRegisteredControlCount() and
GetRegisteredControl(tcControlName|tnControlIndex) to allow the developers
to access the registered controls in the forms. I certainly don't want
somebody to insert items in the RegisteredControls[] array if the items don't
belong there. Note, as an aside, that you can change RegisteredControlCount
to a protected method that returns the number of rows in the
RegisteredControls[] array.

Another example. All my forms can be scaled at runtime (80-320%). I have
terrible eyesight and I like developing big forms in 640x480. My users
have their own preferences and, accordingly, all forms are automatically
resized at runtime. All VFP controls were subclassed and I added some
DesignTop, DesignLeft, DesignHeight, DesignWidth, DesignFontSize, ...
protected properties when appropriate. These properties are set in a
protected SetDesignValues() method that is called in the Init event of the
subclass. My form base class has a protected ScaleResize() method that
sends a 'resize' message to its controls in the Init event. The controls
store the Design values (the ones they are instantiated with) into the
various properties and resize themselves before they are ever displayed.
The reason I keep the original values as properties is all further
resizes are based on the Design values, not on the current values. Sounds
complicated but it's not when you start implementing theses techniques.


>I thought the purpose of 'protecting' a property was that you 'could' use it
> in that class and its subclasses ?

It is. However, a form saved as a form (.SCX) is an instance of the class, not a subclass.

Hope this helps,
Daniel
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform