Partager via


ActiveForm Property

References the active Form object in a form set or the _SCREEN object. Not available at design time; read-only at run time.

Object.ActiveForm.Property [ = Setting]
-or-
Object.ActiveForm.Method

Return Value

  • Property
    Specifies any property of the active form contained in the form set; for example, the Caption property.

  • Setting
    The existing or new setting of the Property.

  • Method
    Specifies any method of the active form contained in the form set; for example, the Move method.

Remarks

Applies To: Form Object | FormSet Object | _SCREEN System Variable

If the containing FormSet object is active, ActiveForm references the Form object that has the focus. If the containing FormSet object is not active, an error occurs.

Use the ActiveForm property to access the active Form object's properties and methods.

Example

This example shows how the ActiveForm property may be used within a menu to enable opening and closing a form. When running this sample, note that the Close menu item in the Window menu pad is only enabled if there is an open form. This behavior is controlled by the SKIP FOR clause in bar 1 of the Wwindow popup, which checks to see if a form is active by testing whether the Name of the form is of the character type. The Name property will be character type if there is an active form; otherwise, the property will be undefined.

SET SYSMENU TO
SET SYSMENU AUTOMATIC

DEFINE PAD _0k50sa3dr OF _MSYSMENU PROMPT "\<Window" COLOR SCHEME 3 ;
    KEY ALT+W, ""
DEFINE PAD _0k50sa3ds OF _MSYSMENU PROMPT "E\<xit" COLOR SCHEME 3 ;
    KEY ALT+X, ""
ON PAD _0k50sa3dr OF _MSYSMENU ACTIVATE POPUP Wwindow
ON SELECTION PAD _0k50sa3ds OF _MSYSMENU DO CloseDemo

DEFINE POPUP Wwindow MARGIN RELATIVE SHADOW COLOR SCHEME 4
DEFINE BAR 1 OF Wwindow PROMPT "\<Close" ;
    SKIP FOR TYPE("_Screen.ActiveForm.Name")<>"C"
DEFINE BAR 2 OF Wwindow PROMPT "\<Open"
ON SELECTION BAR 1 OF Wwindow =_SCREEN.ACTIVEFORM.RELEASE()
ON SELECTION BAR 2 OF Wwindow DO OpenForm

PUBLIC ARRAY aoForms(1)
aoForms[1] = NEWOBJECT("frmdemo")
aoForms[1].SHOW

READ EVENTS

SET SYSMENU TO DEFAULT
CLEAR ALL

    PROCEDURE OpenForm
    DIMENSION aoForms(ALEN(aoForms)+1)
    aoForms[ALEN(aoForms)] = NEWOBJECT("frmdemo")
    aoForms[ALEN(aoForms)].SHOW
    RETURN

    PROCEDURE CloseDemo
    CLEAR EVENTS
    RETURN

DEFINE CLASS frmdemo AS FORM
    CAPTION = "Demo Form"
    NAME = "frmDemo"

    ADD OBJECT cmdClose AS COMMANDBUTTON WITH ;
        TOP = 200, ;
        LEFT = 264, ;
        HEIGHT = 27, ;
        WIDTH = 84, ;
        CANCEL = .T., ;
        CAPTION = "Close", ;
        DEFAULT = .T., ;
        NAME = "cmdClose"

    PROCEDURE cmdClose.CLICK
    m.nOKButton=0
    m.nInfo=64
    =MESSAGEBOX("After this Form closes, select Exit from the menu to return to the Command Window",m.nInfo+m.nOKButton)
    THISFORM.RELEASE
ENDPROC

    PROCEDURE RELEASE
    LOCAL m.nIndex
    FOR m.nIndex = 1 TO ALEN(aoForms)
        IF VARTYPE(aoForms[m.nIndex])=="O"
            IF aoForms[m.nIndex]=THIS
                aoForms[m.nIndex] = ""
                EXIT
            ENDIF
        ENDIF
    ENDFOR
ENDPROC
ENDDEFINE

See Also

Reference

Activate Event (Visual FoxPro)

Deactivate Event

Other Resources

Properties (Visual FoxPro)

Language Reference (Visual FoxPro)