Objects

An object is a real or abstract item that stores data and the operations that manipulate data. Therefore, an object is a collection of one or more properties and associated methods that is described by a class.

A particular object is an instance of a specific class. You can have multiple instances of an object active simultaneously (e.g., multiple windows, multiple buttons).

An object definition consists of two components:

When you create a class, you define a new data type. You can then use that data type to declare objects of that type. Creating objects of a class is a two step process:

  1. Declare a variable of the data type. This informs the PSL code generator that any subsequent references to the variable are associated with the class that was declared, including any method and property references and instantiation expressions. For example, you can define the variable "cif" within the RecordCIF class using the following PSL command:

type RecordCIF cif

  1. Acquire a physical copy of the object and assign it to the identifier (i.e., variable). This process is called instantiating (i.e., creating) the object. For example, you can extract a record from the CIF table and assign it to the variable "cif" using the following PSL command:

set cif = Db.getRecord("CIF","ACN")

You can combine these steps into one PSL statement:

type RecordCIF cif = Db.getRecord("CIF","ACN")

 

The following examples all instantiate objects:

image\tip.gif

Click the image\maxwindow.gif control box to view the intended line breaks in coding examples.


Example 1

type ResultSet rs = Db.select("CID,LNM,BAL","ACN","BAL>:BAL")

Example 2

type ResultSet rs

set rs=Db.select("CID,LNM,BAL","ACN","BAL>:BAL")

Example 3

type RecordDEP dep=Class.new("RecordDEP")

 

image\msgs.gif

The Db.getRecord method returns one existing object. The Db.select method also returns a single object; however, it is a ResultSet that contains zero or more objects of the Row class. The Class.new method creates new objects.


For additional details concerning objects, refer to the following sections:

Object Properties

Object Methods

Object Memory Management

Lexical Scope of Objects

Global Scope of Objects

Casting Objects