Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On Focus and Lost Focus 2

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
I am creating an address gather form and I want to colour the background of the cell which has the focus. I know I can program each of the events seperately, in each cell's Got Focus and Lost Focus procedure but is there a way of assigining this function to all the required cells at run time?

Keith
 
Make your own class and add desired behavior there.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
As I understand it that is ok for single fields. I am trying to speed up the development of projects in general and seem to get bogged down editing each field in turn.
Is there a way of programming these events without having to edit each individual field ie. from a single page 'init' procedure?


Keith
 
As I said, make your own class and use this class instead of VFP native class to bind the fields. That is MUCH easier than any other approach.
If you use VFP8 or VFP9 you could use BINDEVENT to bind GotFocus and LostFocus events to some method in the form.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
I am new to classes but I am always willing to have a go. I need to include some input checking and other field level handling but not every field will be handled in the same way. Should I place a created class control for each field in the form and then further edit each instance at field level to get the individual functionality?

Keith
 
Keith,

You mention "cells". Are you talking about a grid, or do you mean ordinary textboxes?

Also, when you talk about assigning the colour of the cell that has focus, do you mean that as soon as the user tabs to the cell, you want to highlight it with a custom colour, and then return it to normal when they've finished editing?

If so, why not just change the SelectedBackColor property? Or am I missing something?

Admittedly, you would have to do that for every one of the controls, but you can always multi-select them in the designer and apply the change to all of them at once.

That said, I have to agree with Borislav. It would be much more satisfactory to make your own class, and to put the desired behaviour there.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thanks Mike
I am talking about text boxes sorry for the confusion.
I have created my first class as Boris suggested and it works a treat. I have 35 fields on an input form and not knowing which field had the focus was confusing (not easy spotting the cursor when the lamps are going). I wanted to make the field that had the focus, show up so decided to 'make it light up' by changing the background colour. The prospect of having to code each box individually was putting me off, hence the question. I have read about classes but never considered they could be so useful, me being dumb I guess.

The next stage is how to control the form handling. I need to work them out but there will be about 6 different handling options, would the normal procedure be to create a sperate class for each one?

Keith
 
Keith,

Sounds good. You are definitely going about it the right way now.

I know what you mean about it not being obvious which field has focus. I usually set SelectOnEntry, which helps a lot, but some users don't like it.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Keith,
No need to create 6 different classes, create one class, Add a Property in it. That property will show you what handling you need. I.e. in your case you may want some fields to have RED color in GotFocus, Some Fields to have Green, some of them BLUE, and some of them to act like native VFP textbox, so you could do this:
(unfortunately I can't attach a Visual Class here, but you will figured out from this code)
Code:
DEFINE CLASS MyTextBox AS TextBox
    lnWhatColorIWant = 0 && 0 - Act like normal VFP TextBox
    lnOldBackColor   = 0

    PROCEDURE GotFocus()
         this.OldBackColor = this.BackColor
         DO CASE
            CASE this.lnWhatColorIWant == 0
                 *** NOTHING
            CASE this.lnWhatColorIWant == 1 && RED
                 this.BackColor = RGB(255,0,0)
            CASE this.lnWhatColorIWant == 2 && GREEN
                 this.BackColor = RGB(0,255,0)
            CASE this.lnWhatColorIWant == 2 && BLUE
                 this.BackColor = RGB(0,0,255)
         ENDCASE
    ENDPROC

    PROCEDURE LostFocus()

         IF this.lnWhatColorIWant # 0
             this.BackColor = this.OldBackColor
         ENDIF
    ENDPROC

Of course you could use this property to store directly the color value and -1 if you want default behavior.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Thanks for that but a single colour is preferred.
I am now looking at how different fields are handled in the valid function.
Email addresses which contain '@',
First name, Surname, Address 1, Address 2 etc. being populated with text.
Postcode - Looking like a postcode
Phone numbers having only digits in them.
There are a few more and I want to get the data collection right.
I think a seperate class to handle each type is the way to go, at least I will learn more about it as I experiment. I wish I had discovered this a few years ago but there is still so much I do not know about VFP and I am only on V6.


Keith
 
Keith,

Phone numbers having only digits in them.

I usually allow for the fact that some people use parantheses or hyphens when entering phone numbers. Also, "x" for extension.

Postcode - Looking like a postcode

I've got a little function that you're welcome to use:


Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thanks Mike

Phone numbers will only be accepted containing digits as it is likely these will be auto dialed at some point.

I will have a read through the postcode stuff as it looks rather interesting. One of my clients uses a postcode product and his data is fabulous to work with as most of his addresses are exactly right, apart from the occasional manually entered ones.
The postcode is not very important on this app. as it is mainly a telephone or email business.
Now an email veryfier, that would be a useful app but where does email verification end and email spamming begin?


Keith
 
I created a class, let's call it 'a'.
After some experimenting I created two more classes 'b' and 'c' which do what I require.
I have populated the form using 'b' and 'c' and removed the unwanted 'a' from the class library.
Tested the app and all worked well.
Closed down VFP to do another little job and on re-opening up the app, none of the class definitions can be found although they show up in project manager.
Any clues as to what has happened?

Keith
 
Hi Keith,

When you say none of the class definitions can be found, what do you mean exactly? If they show up in the project manager they certainly can't be lost. Perhaps you need to add their location to the SET PATH statement. Or perhaps you need a SET CLASSLIB TO if you are intantiating them using CreateObject(), NewObject() or AddObject()

pamela
 
I have been experimenting with various configurations and once I had the 6 required options, I cleared the class library and removed all the controls from my initial form.
I have dragged the classes from the project manager into the form and further edited each one tt create the app.
The app ran ok until I closed VFP down.
The app is saying it cannot find multiple instances of class 'a' but class 'a' does not exist any more, choosing ignore leaves the form without controls.
Does a form, in some way, remember classes which have been removed.
I have made the form work without classes as I have wasted too much time on it already but am curious to find out what has happened. Don't spend too much time on it, I'll just add it to my list of weird VFP events. I have always liked VFP but have found it not to be as bomb proof as it could be. Keeps us in work I suppose.

Keith
 
Hi Keith,

Does a form, in some way, remember classes which have been removed.

No, but if one of the controls on the form is still based on class a, then the form will complain.

Check the Class property of every control on the form that has the same base class as class a. Or try opening the SCX file as a table and see if class a is referred to in the Class field on one of the records.

pamel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top