12. Working With Classes : How You Can Create User Classes : How You Can Use Attributes and Methods
 
Share this page                  
How You Can Use Attributes and Methods
After you have created your user class, including its attributes and methods, you can relate it to either a frame or another component.
Your application can use the methods and attributes of a user class to process information provided by the application (or the end user or OpenROAD itself), and then take an appropriate action. In the simple example that follows, an error message box is displayed. However, you can use the same principles in creating more complex applications.
To demonstrate some of the concepts in this chapter, follow this example, which uses My_User_Class, one of its attributes, and its method. Note that some steps are abbreviated, since you should already be familiar with how to create or edit basic OpenROAD components.
1. Open My_User_Class or other user class in the Class Editor.
2. Click Tools, Script.
The Script Editor appears, allowing you to define method scripts.
3. Edit the predefined method script as follows:
method my_method ()=
declare
enddeclare
{
     curmethod.infopopup(
               messagetext= 'my_method called!',
               messagetype=MT_ERROR);
}
4. Click Close to save your method script changes and exit the Script Editor.
5. Save the My_User_Class user class component.
6. Create a new user frame, My_User_Frame.
7. Click Tools, Script on the Frame Editor's floating menu bar.
The Script Editor appears, allowing you to define the frame's script.
8. Edit the predefined initialization script as follows:
initialize()=
declare
     v1=My_User_Class
enddeclare
{
     v1.my_attribute=123;
     if v1.my_attribute=123 then
               v1.my_method();
     endif;
}
9. Click Close to save your frame script changes and exit the Script Editor.
10. Save My_User_Frame and then run the frame by clicking Debug, Go.
The following Information window should appear:
Note:  For more information about writing and editing scripts, see Writing Scripts and Procedures (see Writing Scripts and Procedures). For more information about writing the 4GL code for your own user class methods, see How You Can Write Methods in the chapter "Working with Classes" in the Programming Guide.