IUndoRedo.Enabled

Syntax

Enabled: Boolean;

Description

The Enabled property indicates whether the Undo/Redo stack is available for the user.

Comments

If the property value is False, the Undo stack is unavailable. To enable Undo/Redo stack, set the Enabled property to True. After that, all actions executed by the user are saved in the stack and, if required, can be canceled or repeated. The number of operations that can be stored in the stack is limited by the number set in the Limit property.

To cancel the actions done, use the Undo method, to repeat the actions done, use the Redo method.

When value of this property changes, value of the Enable property automatically changes in undo/redo stacks of all child objects.

Example

Executing the example requires a form, the ReportBox and UiReport components placed on this form and the Toolbar1 toolbar that contains five buttons. Create event handlers for the buttons. The UiReport component is a data source for ReportBox.

Class SAMPLEForm: Form
    ReportBox1: ReportBox;
    UiReport1: UiReport;
    Toolbar1: Toolbar;
    ToolbarButton1: ToolbarButton;
    ToolbarButton2: ToolbarButton;
    ToolbarButton3: ToolbarButton;
    ToolbarButton4: ToolbarButton;
    ToolbarButton5: ToolbarButton;
    UnRed: IUndoRedo;

    Sub SAMPLEFormOnCreate(Sender: Object; Args: IEventArgs);
    Var
        MB: IMetabase;
        Report: IPrxReport;
    Begin
        MB := MetabaseClass.Active;
        Report := MB.ItemById("Report_1").Edit As IPrxReport;
        UiReport1.Instance := Report;
        UnRed := Report.UndoRedo;
        UnRed.Enabled := True;
        UnRed.Limit := 10;
    End Sub SAMPLEFormOnCreate;

    Sub ToolbarButton1OnClick(Sender: Object; Args: IEventArgs);
    Begin
        If UnRed.UndoCount > 0 Then
            UnRed.Undo;
        End If;
    End Sub ToolbarButton1OnClick;
    
    Sub ToolbarButton2OnClick(Sender: Object; Args: IEventArgs);
    Begin
        If UnRed.RedoCount > 0 Then
            UnRed.Redo;
        End If;
    End Sub ToolbarButton2OnClick;
    
    Sub ToolbarButton3OnClick(Sender: Object; Args: IEventArgs);
    Begin
        UnRed.Flush;
    End Sub ToolbarButton3OnClick;
    
    Sub ToolbarButton4OnClick(Sender: Object; Args: IEventArgs);
    Begin
        If UnRed.UndoCount > 0 Then
            text := UnRed.UndoState(UnRed.UndoCount - 1).Action;
        End If;
    End Sub ToolbarButton4OnClick;
    
    Sub ToolbarButton5OnClick(Sender: Object; Args: IEventArgs);
    Begin
        If UnRed.RedoCount > 0 Then
            text := UnRed.RedoState(UnRed.RedoCount - 1).Action;
        End If;
    End Sub ToolbarButton5OnClick;

End Class SAMPLEForm;

After executing the example clicking the Button1 button cancels the last executed operation; clicking the Button2 button repeats the canceled operation; clicking the Button3 button clears Undo/Redo stack; clicking the Button4 button displays description of the last operation stored in the Undo stack in the form's text box; clicking the Button5 button displays description of the last operation stored in the Redo stack in the form's text box.

See also:

IUndoRedo