4. Working with Classes : How You Can Manipulate Objects Generically: Casting
 
Share this page                  
How You Can Manipulate Objects Generically: Casting
In developing OpenROAD applications, you generally work with an object of a specific class. For example, when you set the background color for a button, you use the BgColor attribute of the ButtonField class. When your code is compiled, OpenROAD defines the attribute or method specified for the system class or one of its superclasses.
There are occasions, however, when you do not know at development time what object you will be manipulating at runtime. For example, if you want to change the characteristics of a field based on user interaction, such as changing the color of a field as the user enters and leaves it, you must be able to set attributes for an object whose type you do not know as you write the code. To facilitate your writing such generic code, OpenROAD provides special attributes and methods for certain system classes.
FrameExec's TriggerField attribute, for example, lets you detect which field triggered the executing event block. To color‑highlight a field when the user moves into and out of it, you can use the TriggerField attribute to locate the field triggering the Entry and Exit events.
There are also occasions when you code generically with methods. For example, when you send a MessageObject from one frame to another by passing it as a parameter to FrameExec's SendUserEvent method, the receiving frame must know what kind of object to expect.