Examples

The following example shows the type definition of an Indicator control that displays a caption, and is used to indicate an on/off condition. This control is a subclass of the BaseControl class and it has a value property that indicates whether the state of the control is on or off. This property has a mapping method that toggles foreground and background colors when the value property changes. It also reimplements the click and paint events.

The attributes defined for the Indicator class are listed in the following table.

Attribute Name Primitive Type Length
caption String 1000
value Boolean  

The following is an example of a value mapping method.

value(set: Boolean; val: Boolean io) mapping, updating;
vars
    tempColor : Integer;
begin
    if set then
        if val <> value then
            // Swap the foreground and background colors to indicate
            // that the status has changed. This causes a paint.
            tempColor := backColor;
            backColor := foreColor;
            foreColor := tempColor;
        endif;
    endif;
end;

The following are examples of the reimplemented click and paint events.

click(cntrl: Indicator) updating;
begin
    // The following assignment causes the value mapping method 
    // to be executed.
    value := not value;
end;
paint(cntrl: Indicator input) updating;
begin
    drawTextAlign := 2;
    drawTextIn (caption, 0, 0, width, height, foreColor);
    inheritMethod(cntrl);
end;

The following is an example of a constructor method.

create() updating;
begin
    value := false;
end;

The following examples for an ActiveTextBox control (a subclass of the TextBox class) toggle foreground and background colors when the control has focus. The ActiveTextBox control has a toggleColors method that toggles foreground and background colors. It also reimplements the gotFocus and lostFocus event methods that call the toggleColors method.

toggleColors() updating, protected;
vars
    tempColor : Integer;
begin
    tempColor := foreColor;
    foreColor := backColor;
    backColor := tempColor;
end;

gotFocus(textbox: ActiveTextBox input) updating;
begin
    toggleColors;
    inheritMethod(textbox);
end;

lostFocus(textbox: ActiveTextBox input) updating;
begin
    toggleColors;
    inheritMethod(textbox);
end;