User Tools

Site Tools


replace_set_replacement_constructor_or_destructor_.htm
Navigation:  Language Reference > 2 - Program Source Code Format > Prototype Attributes >====== REPLACE (set replacement constructor or destructor) ====== Previous pageReturn to chapter overviewNext page

 

NewC7.jpg

REPLACE

blk2blue.jpg

The REPLACE attribute specifies that the PROCEDURE on whose prototype it is placed completely replaces the constructor or destructor from its parent class. REPLACE is valid only on a PROCEDURE labelled either “Construct” or “Destruct” and declared within a CLASS structure which is derived from a class which also contains a matching “Construct” or “Destruct” PROCEDURE. If the PROCEDURE label is “Construct” the method is a Constructor–automatically called when the object is instantiated. An object is instantiated when it comes into scope or when created with a NEW statement. If the PROCEDURE label is “Destruct” the method is a Destructor–automatically called when the object is destroyed. An object is destroyed when it goes out of scope or when destroyed with a DISPOSE statement.

Example:

 PROGRAM

SomeQueue QUEUE,TYPE

F1         STRING(10)

         END

OneClass  CLASS,MODULE('OneClass.CLW'),TYPE

ObjectQueue &SomeQueue             !Declare a reference to a named queue

Construct   PROCEDURE              !Declare a Constructor

Destruct    PROCEDURE              !Declare a Destructor

         END

TwoClass  CLASS(OneClass),MODULE('TwoClass.CLW'),TYPE

Construct   PROCEDURE,REPLACE      !Declare a replacement Constructor

         END

MyClass   OneClass                 !Instance of OneClass

YourClass  &TwoClass               !Reference to TwoClass

CODE                              !MyClass object comes into scope,

                                  !autocalling OneClass.Construct

YourClass &= NEW(TwoClass)        !YourClass object comes into scope,

                                  !autocalling TwoClass.Construct

DISPOSE(YourClass)                !YourClass object goes out of scope,

                                  !autocalling OneClass.Destruct

RETURN                            !MyClass object goes out of scope,

                                  !autocalling OneClass.Destruct

!OneClass.CLW contains:

OneClass.Construct  PROCEDURE

CODE

SELF.ObjectQueue = NEW(SomeQueue) !Create the object's queue

OneClass.Destruct  PROCEDURE

CODE

FREE(SELF.ObjectQueue)            !Free the queue entries

DISPOSE(SELF.ObjectQueue)         ! and remove the queue

!TwoClass.CLW contains:

TwoClass.Construct  PROCEDURE

CODE

SELF.ObjectQueue = NEW(SomeQueue) !Create the object's queue

SELF.ObjectQueue.F1 = 'First Entry'

ADD(SELF.ObjectQueue)

See Also:

NEW

DISPOSE

CLASS

replace_set_replacement_constructor_or_destructor_.htm.txt · Last modified: 2021/04/15 15:57 (external edit)