10.07.2015 Views

Programming Guide - Actian

Programming Guide - Actian

Programming Guide - Actian

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

How You Can Manipulate Objects Generically: CastingHow You Can Work with AttributesBecause the TriggerField attribute can be used on any field or menu item, youmust make explicit to OpenROAD the class of the object being manipulated inorder for your code to manipulate specific attributes and methods. Castinginvolves making the system class of a generic object explicit.To cast a generic object, enclose its reference variable in parentheses andprecede the parentheses with the name of the subclass to which you want tocast it. If, for example, you want to change the background pattern of a fieldas the user enters it, you use the BgPattern attribute defined for FormField.The following example uses casting to specify that the generic TriggerField isan 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 specificobject is a subclass of the generic one. This casting example is possiblebecause the data type of FrameExec's TriggerField attribute is FieldObject, andFormField and EntryField are both subclasses of FieldObject.Although the class to which you cast a generic object must be in the hierarchybelow the generic object, you can specify any valid class as the type for thegeneric object. For example, to change the background pattern of a field, youcan cast the generic object to FormField or any field below FormField on thehierarchy. The following example works similarly to the previous example, butallows 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 actualobject is not of the same class as, or a subclass of, the class to which you havecast it.Other Attributes Commonly Used GenericallyThe FrameExec system class defines several other attributes that facilitategeneric code development:InputFocusFieldContains the field on the form that currently has the input focus. Thefollowing example demonstrates changing the background pattern of thecurrent field without knowing its name:CurFrame.InputFocusField.BgPattern = FP_SHADE;This example does not require casting because the data type of theInputFocusField attribute is ActiveField, and ActiveField is a subclass of thesystem class (FormField) for which the BgPattern attribute is defined.140 <strong>Programming</strong> <strong>Guide</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!