Thursday, July 23, 2015

VFP small tricks

1. Control text format in Textbox and other input controls

InputMask Property
Specifies how users enter data and how to display data in a control. Available at design time and run time.

Format Property
Specifies the input and output formatting of a control's Value property. Available at design time and run time.


2. Move cursor to the right in a textbox

This.SelStart = LEN(ALLTRIM(This.Value))
This.SelLength = 0



3. Multiple forms - Modal vs Modeless

 Modal forms require user input. A modal form has exclusive focus until it is dismissed. When showing a modal form, the controls outside the modal form will not react until the modal form is closed.
http://fox.wikis.com/wc.dll?Wiki~ModalvsModeless

The property "Desktop" of child form specifies whether a form can appear anywhere on the Windows desktop (if the value is .T.) or is contained in the parent form ( if the value is .F.). The default value is .F.

4. Prevents Visual FoxPro from inserting a key press into the keyboard buffer

Including NODEFAULT in the KeyPress event procedure or function prevents Visual FoxPro from inserting the key press into the Visual FoxPro keyboard buffer. Therefore, you can create a KeyPress procedure so that you can test which key is pressed before the key is sent to the keyboard buffer.
https://msdn.microsoft.com/en-US/library/e525z4k3(v=vs.80).aspx


5. Print immediately

Put these two lines at the end of program:

SET PRINTER TO
SET DEVICE TO SCREEN

Monday, July 13, 2015

VFP: Cancel validation on exit button click


Question:

In a Form, I have several textboxes that are validated against a table. The only logical way to set up the screen is for one of them to have the focus when you enter the form or after a save and ready for the next input (this textbox determines what all the rest have in them [e.g., the order number]). I also have a standard EXIT button which has Thisform.Release().

When I click the EXIT, the Valid() on the order field fires first and I must validate it before I can exit. My current work-around is to set the form's Key Preview on and check for ESCAPE and release.

How can I know in the Valid for order what event caused the valid to fire (i.e., the exit click) so I can conditionally skip the valid and let the form release?

I know I have seen this somewhere but can't remember.

Thanks,

==========================================

Answer:

There are a number of advantages of using an Exit button with the Cancel property set to .T. and checking for LastKey() = 27 in the Valid events of all of your control classes. One is that with Cancel set to .T. clicking the button is the same as pressing Escape so checking for 27 (Escape) as the LastKey() will tell you if the Exit button has been clicked. Secondly with Cancel set to .T. pressing Escape will click the button and fire its Click event thusly allowing you to give the user an expected functionality for the escape key.

In my control classes the beginning of the Valid event is;

IF LastKey() = 27
   Keyboard "{CTRL+A}"
   RETURN .T.
ENDIF


The keyboard of CTRL+A is to change the value of LastKey() from 27. This is because if the user clicks the exit button and then only uses the mouse, lastkey() will remain 27 until some other key is pressed. Doing the keyboard changes lastkey from 27 so the only way it can be 27 again is by pressing escape or clicking a button that has Cancel set to .T.


http://fox.wikis.com/wc.dll?Wiki~SkipValidOnExit

Wednesday, July 8, 2015

VFP Form Event Sequence

 -When A Form Getting Loaded:
  1. DataEnvironmet.openTables()
  2. DataEnvironmet.beforeOpenTables()
  3. Form.load()
  4. [cursurs].Init()  - for each cursor in DataEnvironment
  5. DataEnvironment.init()
  6. [controls].init() -  for all controls in a form
  7. Form.init()
  8. Form.show()
  9. Form.activate()
  10. Form.refresh()
  11. [object1].when()  – for the first object in tab order
  12. [object1].gotFocus()  – for the first object in tab order

But In MSDN There Is A Slight Difference:
  1. Form.init()
  2. Form.activate()
  3. [object1].when()  – for the first object in tab order
  4. Form.gotFocus()
  5. [object1].gotFocus()
  6. [object1].message()

-If We Leave An Object And The Next Object Gets The Focus:

Whenever An Object Gets The Focus The Sequence Of The Events Is As Below:
  1. [object(i)].when()
  2. [object(i)].gotFocus()
  3. [object(i)].message()

And Whenever An Object Loses The Focus The Sequence Would Be:
  1. [object(j)].valid()
  2. [object(j)].lostFocus()

-If We Move To The Next Text Box From Currently Focused Text Box And Type Something In The Next Text Box:
  1. Text(i).keyPress()
  2. Text(i).valid
  3. Text(i).lostFocus
  4. Text(i+1).when()
  5. Text(i+1).gotFocus()

-When We Type In A Text Box:
  1. Text(i).keyPress()
  2. Text(i).interactiveChange()

-When We Leave A Form By Calling Realease() Method (Closing The Form):
  1. Form.queryUnload()
  2. Form.destroy()
  3. Form.[command buttons].destroy()
  4. Form.[objects].destroy()
  5. Form.unload()
  6. DataEnvironment.afterCloseTables()
  7. DataEnvironment.destroy()

-When We A Form Loses Focus (Like When Another Form Get The Focused):
  1. Form.lostFocus()
  2. Form.deactivate()

Che - 10/APR/2007
http://fox.wikis.com/wc.dll?Wiki~FormEventSequence