New Switchbox Class (Revised & Enhanced)
I have made further enhancements (2 new themes) and modifications (like renaming _type to _theme, removing _ivalue, allowing _value to accept either a logical or integer value then return the same, and some more) inside the class so I decided to rewrite this blog instead of cluttering the bottom part with lots of updates/notes; here which will make it longer. So here is the revised blog:As I have said before, I love simple things as sometimes those simple things are what's contributing to the bigger picture. My intention for this class is to replace the checkbox with something unique/unusual. Although for simple needs of toggling a return value of .T. or .F. or 1 or 0 checkbox is the best thing to turn to, It does not hurt to replace it with something a little bit unique which may add "appeal" to our form. Presenting switchbox:
Q: So how can we use this new class?A: As usual with classes you just need to drag it inside your form. Then in the init event of the instance of the class is where you need to assign the switchbox' different properties like theme and caption. In the image shown above, I used something like this:
Switchbox1 Init:
this._theme = 5
this._value = .T.
Note: Default settings follow:_value = .F.
_theme = 1
_caption = None
Q: What does None in the default caption means?A: In the tradition of VFP, in an absence of assigned caption, it will get the name of the of the object. So when you don't touch the _caption property you will be seeing something like Switchbox1, Switchbox2....
Q: For whatever reason, I don't want to put any caption on the switchbox. Can I simply show the switchbox without any caption?A: Yes! Just place in the init event of the instance of the class:
This._caption = ''
Q: A checkbox class has a Click Event where we can place commands. Can we do the same with switchbox?A: Yes, but you need to use SwitchBox' Shape1 Click Event for that and combine it with DODEFAULT(), something like this:
SwitchBox Shape1's Click Event:
DODEFAULT()
* Do something here
Q: What are the possible return value of this class?A: Like the checkbox class, this class will return an integer value of 1 (ON state) or 0 (OFF state) or .T. (ON state) or .F. (OFF state) depending on the declaration used via _value property. By default as mentioned though, it is set to a logical value of .F..
?thisform.SwitchBox1._value && will return either .T., .F., 1 or 0 depending on the initial value we assign
Q: How about if we want the switchbox to start in an ON state? A: Just add any of these in the init event of the instance of the switchbox object inside the form:
this._value = 1 && sets it to ON state initially, _value to be returned is either 1 or 0
this._value = .T. && sets it to ON state initially, _value to be returned is either .T. or .F.
this._value = 0 && sets it to OFF state initially, _value to be returned is either 1 or 0
Q: Checkbox can be toggled via clicking on its caption. Does this one have that attitude too?A: Yes it does.
Q: The images seem to be tied up in C:\Switchbox, how to make it work regardless of the path?A. On all the samples I gave, I do that to insure that interested users will properly see the images on the development stage. However, if you want to remove that binding on specific folder location, do these:
Remove the hardcoding of path I made inside the class on all occurrences; then add the images into your own project (other, other files, add). One problem with that as I have said is you won't see those images while still in the developing stage. Those will be reflected properly only in the exe:
Search all harcoding of path instances within the class, from:This.Parent.Image1.Picture = "c:\switchbox\swbox"+Iif(This.Parent._value = .F.,"on","off")+ transform(This.Parent._theme)+".bmp"
Into:This.Parent.Image1.Picture = "swbox"+Iif(This.Parent._value = .F.,"on","off")+transform(This.Parent._theme)+".bmp"
The class I will give you includes 2 samples, the one shown above and this other one, replacing checkbox in a grid with something like this:

Cool?
I have been a little bit intrigued by Emerson's message that interested party may request a beta of his very cool new project instead of simply attaching a sample in that blog but thinking about it, yeah I love his new way, maybe not for the same reason that in mine is I would love to know who will be interested in this class for I was not able to know who had shown an interest on some of my previous ideas except for those who notify me by way of comments or email.
So for the first time, I will not be providing a link where you can download an attachment of this one. If you are interested in this, post a comment below with your email address and I will be sending it to you. Post the request here under the comment section, not inside the forum.
Sounds fair? Then I will say in advance to those who will be interested in using this class, Enjoy!
P.S. I would like to thank some guys in pointing to me some misrepresentation in the original blog content like
Woody and
Mike Podjer whom without their comments I will simply fail to see such.
Update: December 26, 2009
I already have submitted the classes for free and easy download to Eric
for the download section of foxite, so you will see those pending the
decision of Eric. In addition, I have created a thread in coderisland
to have the same available for download. Please click on the link
below:
http://www.coderisland.com/forum/viewtopic.php?f=10&t=254