there's a very easy way to get around the problem with the toolbar not receiving focus. I believe you merely reset focus to the current control.

I'm not sure what you're saying.

Try this:

Create a toolbar class with one command button on it. In that command button's Click() event method, put the following code:

MESSAGEBOX("Saving data, then quitting.")

WAIT "" TIMEOUT 3

_SCREEN.ActiveForm.Release()

Then create a form as follows:

Add a property to the form called oBar and set it to .NULL.

Add a textbox and a command button to the form. Make sure TabIndex of the textbox is 1 and the button is 2.

In the Valid() event method of the textbox, put the following code:

IF "invalid" $ LOWER(THIS.Value)
     RETURN .F.
ELSE
    RETURN .T.
ENDIF

In Form.Init():

LOCAL oToolBar

oToolBar = NEWOBJECT("MyToolBarClass","MyToolBar.vcx")

THISFORM.oBar = oToolBar

THISFORM.oBar.Visible = .T.

In Form. Destroy():

THISFORM.oBar.Release()

THISFORM.oBar = .NULL.

Now run the form. See the toolbar and form appear.

In the textbox, type "invalid" and hit the TAB key. Notice you can't leave the textbox.

Now, click the button on the toolbar. Watch the messagebox tell you that your invalid data is being saved. Click OK on the messagebox, then wait 3 seconds and watch the form and toolbar disappear.

Remember, this is about using Valid() to prevent invalid data from being entered.

Yes, in the click of the toolbar button you could call code to check the validity of the data in the textbox and reset focus to that control if it doesn't pass. But if you're going to do that, you might as well just have all of your validity tests called just before you execute your save method and return .F. while displaying a helpful explanation of the problem and how to fix it. Then you don't have to mess around putting code into every Valid() method.

The only reason this wouldn't be better in most cases is if you are binding data to controls, which, IMO, is not a good idea.

VFP has all kinds of RAD stuff, but often, RAD is BAD design. :)

Ken Dibble
www.stic-cil.org





_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to