Access a public data member of a class instance

After you have created an instance of another class, you can access any PUBLIC data member in the class instance. Here is the simplified syntax for accessing a PUBLIC data member of a class:

<ref>:<data-member> 

Syntax Element

Description

ref

The variable or property that holds the reference to the instance of the class.

data-member

The name of the data member in the class. This data member must be PUBLIC.

Suppose you have defined some of the data members of the Emp class to be PUBLIC. For example, the phone numbers, address, and postal code data members for an Emp are defined as PUBLIC because you want to be able access them from the Dept class and from other parts of the application. Here, in the AddEmployee() method of the Dept class, we have created the instance of the Emp class and assigned it to Emp. The PRIVATE data members of the Emp class must be set by calling the Initialize() method of the Emp class. The PUBLIC data members of the Emp class can be set from the Dept class. In this code, we assign values to the Address, Phones, and PostalCode data members of the Emp class instance using the reference to the Emp instance.

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 (). 
	// call Initialize() method to initialize the private data 
    // members for the Emp Instance  
  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 variables and data elements and Comparison with procedure-based programming user-defined functions.