Call a public method of a class instance
- Last Updated: August 17, 2021
- 1 minute read
- OpenEdge
- Version 12.2
- Documentation
After you have created an instance of another class, you can call any
PUBLIC constructor, method, or destructor defined
in the class. If a method returns a value, you can use that value anywhere in your code.
Here is the simplified syntax for calling a method of a class:
<ref>:<method>( [ <parameter>][,…]).
|
Syntax Element |
Description |
|
|
The variable or property that holds the reference to the instance of the class. |
|
|
The name of a method defined for the class. |
|
|
Zero or more values that are passed to the method at run time. The types of the parameters must match the parameters defined for the method in the class definition. |
PACKAGE-PRIVATE or PACKAGE-PROTECTED constructor or method defined in the class if they are
in the same package. Here is the AddEmployee() method of the
Dept class. You call the PUBLIC
Initialize() method in the Emp class using the reference to the Emp
instance. When we call Initialize(), you pass values
that match the number and type of parameters defined in the Initialize() method of the Emp class.
Note that the values passed into the Initialize()
method were passed in to the AddEmployee() method of
the Dept class.
method public void AddEmployee (input pEmpNum as integer,
input pFirstName as character,
input pLastName as character,
input pAddress as character,
input pPostalCode as character,
input pPhones as character extent 3,
input pVacationHours as integer,
input pJobTitle as character ):
define variable Empl as Emp no-undo. Empl = new Emp ().
Emp:Initialize(pEmpNum,pFirstName,pLastName,pAddress,
pPostalCode, pPhones, pVacationHours, pJobTitle).
create ttEmployee.
assign ttEmployee.FirstName = pFirstName
ttEmployee.LastName = pLastName
ttEmployee.EmpRef = pEmpl
NumEmployees = NumEmployees + 1 .
return.
end method.
For more information, see Comparison with procedure-based programming invoking internal procedures.