ZOrder
ZOrder is a method of controls that manipulates which control is on top of a stack of overlying controls, but, far more importantly (and far less documented!), also controls the firing order of key events for a set of controls on a form. The fact that there's no equivalent property for finding out who's on top makes this a pain in the neck to work with.
Usage |
oControl.ZOrder( nWhichWay ) |
Parameter |
Value |
Meaning |
nWhichWay |
0 |
Bring the designated control to the top of the stack. |
1 |
Push the designated control to the bottom of the stack. |
If the form is generated from code rather than an SCX, each Init fires in the order it's specified with ADD OBJECT in the form's definition, and is unaffected by ZOrder. Our third example demonstrates this. In a coded form, all the Inits still fire, regardless of whether you ZOrder a control to the top of the stack. In a visually designed form (an SCX), an Init that forces its control to the front (by issuing the command This.ZORDER(0)) prevents the other controls' Inits from running. Bear this in mind if you mess with ZOrder and try to convert a form from visual to hand-coded. |
During the Destroy events, attempting to push the ZOrder of a control back "over" controls that may have already been destroyed can crash FoxPro with an "Invalid Page Fault." |
Example |
* Here's a sample program that tests what ZOrder() will do * The first creates an infinite loop, the second misses * firing the Refresh() of one of the controls, and the third * shows how the rules are different for Init()s in coded (vs. * graphically designed) forms. PRIVATE nDirection * 1st example: Looping form * Press any key other than Enter or Spacebar to stop the show. WAIT WINDOW "An infinitely looping form" nDirection = 1 && force the control to the back oForm = CREATEOBJECT('BadForm') oForm.Show() oForm.Release() * Second example: Button2's Refresh never fires WAIT WINDOW "Form that skips Button2's Refresh" nDirection = 0 && force the control to the front oForm = CREATEOBJECT('BadForm') oForm.Show() oForm.Release() * Last example: Inits in coded forms all fire WAIT WINDOW "Form with Inits that should skip but don't" nDirection = 0 && force the control to the front during Init oForm = CREATEOBJECT('BadForm2') oForm.Show() oForm.Release() RETURN DEFINE CLASS BadForm AS Form ADD OBJECT btnCommandOne AS btnCommand WITH Top = 10 ADD OBJECT btnCommandTwo AS btnCommand WITH Top = 50 ENDDEFINE DEFINE CLASS btnCommand AS CommandButton PROCEDURE Refresh WAIT WINDOW "Hello, I'm " + this.name + ; "'s Refresh Event" + chr(13) + ; "Refresh Events fire in ZOrder()." + chr(13) + ; "Press Enter to continue," + ; " any other key to quit " ; TO cTheirAnswer IF EMPTY(cTheirAnswer) This.ZOrder(nDirection) && change order ENDIF ENDPROC ENDDEFINE DEFINE CLASS BadForm2 AS Form ADD OBJECT btnCommandOne AS btnCommand2 WITH Top = 10 ADD OBJECT btnCommandTwo AS btnCommand2 WITH Top = 50 ENDDEFINE DEFINE CLASS btnCommand2 AS CommandButton PROCEDURE Init WAIT WINDOW "Hello, I'm " + this.name + ; "'s Init Event" + chr(13) + ; "Hand-coded Init Events all fire " + ; "regardless of ZOrder()." + chr(13) + ; "Press Enter to continue" This.ZOrder(nDirection) && change order ENDPROC ENDDEFINE |
See Also |