System Functions
NEW( ) Create New Object
   
Formats 1. Create Object: NEW(class$[,param1[$], param2[$],...] [ FOR dependancy ][,ERR=stmtref] )
2. Clone Object: NEW(obj_id [ FOR dependancy ][,ERR=stmtref] )
 
Where:
class$ Object identifier of an existing Object. The cloning process does not run the On_Create for the new clone nor provide access to files from the original
dependancy Other object, window, file, control or such that this object is dependant on. This this other item is deleted from the system, the object will also be deleted. See Dependancies below
stmtref Program line number or statement label to which to transfer control.
   
Returns Object Identifier.
   
Description The NEW( ) function is used in Object Oriented Programming to create a new object based on a specified class name or an existing object (obj_id). If the class name already exists, then its definition is used. If it has not been defined previously, the system attempts to load the program class.pvc and execute/define the DEF CLASS within it (the DEF CLASS clause must be at the start of the program). If the system is unable to properly determine the class definition, an Error #90:"Unable to locate Object class definition" is generated.
In the example below, if the class definition for Customer does not already exist in memory, then the system attempts to load the program Customer.pvc:
Cst = NEW ("Customer")
If this is successful, the NEW( ) function returns the object identifier assigned to the object. The label ON_CREATE is called to initialize the object (if ON_CREATE logic exists in the class definition). Optional parameters can also be used with the NEW( ) function to be passed on to the ON_CREATEentry point; e.g.,
C = NEW("Customer", File_number)
In Customer.pvx:
0010 ON_CREATE: ENTER File_no


*Note* Use REF( ) to increment the reference count.


Dependancies The OOP interface included in PxPlus has been enhanced to allow for the automatic linking of objects to other system components, such as, Programs, Windows, Controls, Files and other Objects. As these other components are closed or deleted, its linked objects will automatically have their usage count decremented. Potentially, the linked objects could also be freed up.

This feature allows programmers to leave much of the housekeeping logic related to objects up to the system, as opposed to having to worry about coding for it themselves. By linking objects to items such as the current window, the programmer no longer needs to worry about dropping the object when the window is deleted.

To establish this linkage the NEW function has been enhanced to include a "FOR" option where the programmer can specify the component that will be linked to the object.

Syntax: causes the object to be deleted when..
NEW(..... FOR WINDOW) .. the current WINDOW is destroyed
NEW(..... FOR CONTROL ctlid) .. the specified control is destroyed
NEW(..... FOR FILE fileno) .. the specified file is closed.
NEW(..... FOR OBJECT [ objid ] ) .. the current object or object specifed is destroyed
NEW(..... FOR PROGRAM) .. the current program is exited.

Where:

ctlid is the control identifier that will be linked to the object.
fileno is the file number that will be linked to the object.

Object Dependancies are an +PxPlus Exclusive

   
   
   
See Also Object Oriented Programming
DEF CLASS Directive
REF( ) Function