Use the cast function to access a class instance dynamically
- Last Updated: January 16, 2024
- 1 minute read
- OpenEdge
- Version 12.8
- Documentation
Use the cast function to access a class instance dynamically
Here is a simple example of using the ABL cast() function. A temp-table,
ttEmployee, has been defined. It contains employee
records.
A class instance is created dynamically in the
GetEmployee() method of the Dept to find employees
based on the first and last name in the ttEmployee temp-table.
If an employee is found, it should cast the EmpRef field and return the
Emp instance. If an employee is not found, it should return
unknown. Once the object reference is cast to the correct
type, you can execute any method of that
instance.method public Emp GetEmployee(input pFirstName as character, input pLastName as character):
find first ttEmployee where ttEmployee.FirstName = pFirstName and
ttEmployee.LastName = pLastName.
if available (ttEmployee)
then
return cast(ttEmployee.EmpRef,Emp).
else
return ?.
end method.