Lexical Scope of Objects

The Lexical Scope of an object defines the places or points in time at which an object is accessible or available. When you call a procedure, the calling routine passes objects to the procedure through its formal parameters, or as variables.

Example 1

function (par1,par2,RecordCIF par3)

// par1 - string parameter 1

// par2 - string parameter 2

// par3 - object parameter

set par3.taxid = "123-45-6789" // par3 is an object of type RecordCIF

quit par3 // returns object of type RecordCIF to caller

 

If you pass an object as a variable, you must re-declare the object within each procedure that references it with the type command. The new and kill commands terminate the scope of declarations previously defined within the same or higher stack level.

Example 2

new a

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

if a.lnm = "Smith" { // a points to CIF object

new a

type a = Db.getRecord("DEP",":CID") // a points to DEP object

// CIF object on stack

}

set a.lnm = "Jones" // DEP object gone

// a points back to CIF object