Programming Guide : Working with Classes : How You Can Manipulate Objects Generically: Casting : How You Can Work with Attributes
 
Share this page          
How You Can Work with Attributes
Because the TriggerField attribute can be used on any field or menu item, you must make explicit to OpenROAD the class of the object being manipulated in order for your code to manipulate specific attributes and methods. Casting involves making the system class of a generic object explicit.
To cast a generic object, enclose its reference variable in parentheses and precede the parentheses with the name of the subclass to which you want to cast it. If, for example, you want to change the background pattern of a field as the user enters it, you use the BgPattern attribute defined for FormField. The following example uses casting to specify that the generic TriggerField is an entry field and changes the background pattern of the field to shaded.
EntryField(CurFrame.TriggerField).BgPattern =
    FP_SHADE;
You can cast a generic object to a more specific object only if the specific object is a subclass of the generic one. This casting example is possible because the data type of FrameExec's TriggerField attribute is FieldObject, and FormField and EntryField are both subclasses of FieldObject.
Although the class to which you cast a generic object must be in the hierarchy below the generic object, you can specify any valid class as the type for the generic object. For example, to change the background pattern of a field, you can cast the generic object to FormField or any field below FormField on the hierarchy. The following example works similarly to the previous example, but allows all form fields to trigger the change in background pattern:
FormField(CurFrame.TriggerField).BgPattern =
    FP_SHADE;
When you cast an object, OpenROAD produces an error at runtime if the actual object is not of the same class as, or a subclass of, the class to which you have cast it.
Other Attributes Commonly Used Generically
The FrameExec system class defines several other attributes that facilitate generic code development:
InputFocusField
Contains the field on the form that currently has the input focus. The following example demonstrates changing the background pattern of the current field without knowing its name:
CurFrame.InputFocusField.BgPattern = FP_SHADE;
This example does not require casting because the data type of the InputFocusField attribute is ActiveField, and ActiveField is a subclass of the system class (FormField) for which the BgPattern attribute is defined.
OriginatorField
Contains the field defined in the on event statement that originated the specified event. For example, assume that you code a ChildExit event block for a composite field (On ChildExit CompField). Whenever the user exits any of the child fields composing CompField, the OriginatorField attribute contains the composite field name, CompField. In contrast, the TriggerField attribute contains the name of the specific child field that the user exited.
This attribute is particularly useful when you have multiple events defining the same event block. For example, if you have a radio field and menu list that you use to enable multiple interfaces to the same action and you want to keep them synchronized, you could use the following code:
on click TestRadioField,
on click TestMenuList =
begin
if CurFrame.OriginatorField =
    field(TestRadioField)then
    TestMenuList = TestRadioField;
else
    TestRadioField = TestMenuList;
endif;
/* common code goes here */
end;
TargetField
Contains the name of the field that will next have the input focus (assuming the focus is not moved)