IsEnabled - cCJAction

Function which indicates if an action should be enabled

Type: Function

Return Data Type: Boolean

Parameters: None

Return Value

Returns True if item should be enabled, False if not


Syntax
Function IsEnabled Returns Boolean

Call: Get IsEnabled to BooleanVariable


Description

IsEnabled is a function that the developer should use to determine if an item should be enabled or not. This is used by the Update method to set the object's pbEnabled state. Update is called before a popup menu item is displayed, during an idle timer update (if pbActiveUpdate is true) and at the end of the Execute method. In addition, if IsEnabled is false, the OnExecute event will not be sent. Therefore, if you place the required logic inside of IsEnabled to determine if an item is enabled your menu items will always properly display this state.

By default IsEnabled returns the value pbEnabled, which means that by default it always returns the current state of the object.

Note:You should never change the value of pbEnabled within IsEnabled. The only purpose of IsEnabled is to determine if the object should be enabled and not if it is currently enabled.


In this example, we assume that the message ToggleReadOnly and the property pbReadOnly have been defined at the cCJCommandBarSystem object level (this is a hypothetical sample). Note that pbEnabled is never explicitly set - it will be set as needed when Update is called.

Object oReadOnlyMenu is a cCJMenuItem
    Set psCaption to "&Read Only"
    Set psToolTip to "Read Only"
    Set psDescription to  "Set or Clear system read only status"

    Procedure OnExecute  Variant vCommandBarControl
        Handle hoCommandBar 
        Get CommandBarSystemObject to hoCommandBar
        Send ToggleReadOnly of hoCommandBar
    End_Procedure

     Function IsEnabled Returns Boolean
        Boolean bReadOnly
        Handle hoCommandBar 
        Get CommandBarSystemObject to hoCommandBar
        Get pbReadOnly of hoCommandBar to bReadOnly
        Function_Return (Not(bReadOnly))
     End_Function

End_Object

Active Updates

If this item was used in a popup menu, there would be no need to set pbActiveUpdate to true. Update is sent to this item before it is popped up and therefore it will always be correct. If this item were used in a toolbar, setting pbActiveUpdate to true ensures that this will refreshed via the idle timer (if pbTimerUpdate is true) and will always reflect the latest changes.

See Also

IsChecked | IsVisible | pbChecked | pbEnabled | pbVisible | Update