Workbench User Guide : 12. Working With Classes : How You Can Create User Classes : Create Methods for a User Class
 
Share this page                  
Create Methods for a User Class
The data type of an attribute or method can be either a simple data type or a class, including another user class. If a user class is defined as the data type, the user class must exist before you create the attribute or method.
You can create a method for a user class using the Class Editor.
When you define methods for a user class, you specify:
The name by which they are invoked
A data type for the return value (can be nullable)
A remark describing the attribute
To create a method for a user class
1. Select the application that contains the user class in the Applications portlet of the Develop tab.
2. Double-click the user class in the Components portlet.
The Class Editor is opened.
3. Click the Methods tab in the Class Editor.
4. Click Edit, Insert, New.
The Create Method dialog appears.
5. Enter a name for the method in the Name field (for example, my_method).
6. Select the Private (Encapsulation) option if you want to specify this method as private, meaning that the method is only accessible to this user class and its subclasses.
7. Specify the return value for the method.
8. Click Create.
The dialog changes to the MethodProperties dialog.
Like the AttributeProperties dialog, this dialog lets you specify or edit a method's properties if you did not do so previously.
For descriptions of the properties of user class methods, see Properties for User Class Methods.
Note:  You can click the New button to access the Create Method dialog again to create additional methods.
9. Define any other property settings.
10. Click Close.
Workbench displays the method on the Methods tab of the Class Editor.
11. Click File, Save and Close to save your changes to the user class.
Properties for User Class Methods
The following are descriptions of properties that you can set for a user class method:
Name
Specifies the name of the method. This name must be a valid OpenROAD name.
Important!  In OpenROAD, the following objects can be named: applications, classes, components, databases, database tables and columns, parameters, procedures, user events, and variables. The rules for these names, or alphanumeric identifiers, are as follows:
Names can contain up to 32 characters.
Names must begin with an alphabetic character or an underscore (_).
In addition to letters and numerals, a name may contain these characters: #, @, and $.
Names are not case sensitive.
A name may not be a reserved word (see the 4GL Keywords section in the “System Constants and Keywords” appendix of the Language Reference Guide).
Note:  You cannot change this property at runtime because 4GL cannot dynamically use different variable names for the same object.
Remark
Specifies a description of the method
Encapsulation
If the Private option is selected on the Create Method dialog, specifies that the method can be accessed only by a method of the current user class or any of its subclasses.
Note:  In object‑oriented programming, you can limit access to an object's attributes and methods. The process of allowing only the object itself to have access to its attributes and methods is called encapsulation. In OpenROAD, you accomplish this restriction by flagging an attribute or method as private. You can only reference a private attribute or method in the 4GL code of the methods of the defining user class or its subclasses. For more information, see Encapsulating Attributes and Methods in the chapter “Working with Classes” in the Programming Guide.
Return Value
Specifies the variable type of the method:
None
Simple
Reference
Array
Data Type
Specifies the data type of the method for simple type variables only. Valid options are:
Varchar
Nvarchar
Integer
Smallint
Float
Decimal
Date
Money
Length
Specifies the maximum number of characters of the method's return value for simple type variables, varchar, and nvarchar data types only
Nullable
Specifies that a null value is allowed for simple type variables only
Class Name
Specifies the name of a system class or another user class in the current application or an included application for reference or array variables only
Extended Properties
Specifies the set of TaggedValue entries for this method.
For a detailed description, see Properties for User Class Attributes.
Write 4GL Code for Your Methods
You define all of a user class's methods in a single 4GL script that is part of the user class source object. Any operations that can be performed syntactically in the 4GL code of a frame or procedure can be done in the 4GL code of a user class method, including invoking another of the class's methods.
The methods created in the script must correspond to methods defined for the user class. (For the syntax for method scripts, see the Language Reference Guide).
To write the 4GL code for your methods
Click Tools, Script in the Class Editor.
Workbench opens the Script Editor (or your system editor) for you to write the code for your methods.
You write one script for all the methods of a user class. Writing one such method script is covered in How You Can Use Attributes and Methods.
Edit an Individual Method
You can edit an individual method using the Class Editor.
To edit an individual method
1. Select the application that contains the user class in the Applications portlet of the Develop tab.
2. Double-click the user class in the Components portlet.
The Class Editor is opened.
3. Click the Methods tab.
4. Select the name of the method.
5. Click Edit, Properties.
Alternatively, position the mouse cursor on the name of the method and click the secondary mouse button.
The MethodProperties dialog appears.
6. Change any of the method's properties as desired.
For descriptions of user class attribute methods, see Properties for User Class Methods.
7. Click Apply and then Close to close the MethodProperties dialog.
8. Click Tools, Script to edit the script for a user class method.
Workbench calls the Script Editor (or your system editor) for you to edit the code for your methods.
9. Click Close to save your script changes and exit the Script Editor when you have finished editing the method.
10. Click File, Save and Close in the Class Editor.
Edit a Method's Tagged Values
You can edit the method tagged values in the Extended Properties Editor. For a detailed description, see Edit Tagged Values for a User Class, Attribute, Method, Field, or Frame.
To open the Extended Properties Editor, click the Extended Properties edit button.
Delete a Method
You can delete a method using the Class Editor.
To delete a method
1. Select the application that contains the user class in the Applications portlet of the Develop tab.
2. Double-click the user class in the Components portlet.
The Class Editor is opened.
3. Click the Methods tab.
4. Select the name of the method to be deleted.
5. Click Edit, Delete.
The method is deleted.