Invoke object methods
- Last Updated: December 22, 2023
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
In addition to attributes, some objects support methods. A method is an operation that performs a specific action related to an object. You can think of methods as being very much like the built-in functions the language supports. The methods are also identified by keywords that you use in ABL syntax following an object reference, which can be the object name or handle followed by a colon, just as for attributes:
|
Methods typically take one or more arguments, defined in a comma-separated list in parentheses following the method name.
For example, later you learn how to view a text field as an editor, with multiple lines
and scrollbars and so forth. There is an editor method, called
READ-FILE, that you can use to open and read an operating system
file into an editor, just as the Procedure Editor does. READ-FILE takes
a single argument, the name of the file to read. So this sample syntax reads a file into
an editor called cEditor:
|
Methods always return a value, just as built-in functions do. Generally, that value is a LOGICAL indicating whether the operation succeeded or not (with a TRUE value indicating success). You can assign the return value to a variable or field in an assignment statement:
|
The initial letter l indicates that this is a logical variable.
You can also ignore the return value (as you can with any function) and simply treat the method reference as a statement of its own:
|
Some methods return more meaningful values that you would normally not ignore. Indeed,
some methods exist solely to return a meaningful value. You can think of these methods
as being similar to attributes. However, because an input parameter is required and
attribute references cannot take parameters, you use a method instead to retrieve the
return value. For example, the following code sample uses an ABL system-wide object
called FONT-TABLE to calculate the width of a button label in the
current font. It then uses this value to calculate the required width of a frame that
has five buttons. Because the button label must be passed in to the operation, the
syntax must be defined as a method (in this case called
GET-TEXT-WIDTH-CHARS) rather than an attribute (which might have
been called TEXT-WIDTH-CHARS):
|
As you can see from this example, you can reference the method within an expression anywhere another value could appear.