INIT

 (Available in 00 TS Tools(Base) - TS_Tools_Root1)

Purpose

Create a 'TS_Root0' instance

Syntax

oRoot0:=TS_Root1{ [oOwner][,[#NameOfTheInstance][,[TRUE] ] ] }

Arguments

uoOwner
NIL, OBJECT
usymNameSym
NIL, SYMBOL
uloSelfDestruct
NIL, LOGIC, OBJECT

Description

This class serves no purpose on its own, the class should be used as a derived from class when defining you own application classes.

Above the properties and methods of the TS_Root0 class, this class supports the 'SelfDestructOnUnRegisterOwner' and the 'Owner' properties

Note: If the 'uloSelfDestruct' parameter is TRUE and no owner for the class is provided a error will be signaled and the object is invalidated.

Note: Passing an object as the'uloSelfDestruct' parameter is only allowed if this class is an instance of 'TS_Root2' otherwise an error will be signaled, and the object is invalidated.

Example

CLASS SomeCLass INHERIT TS_Root1

METHOD INIT( ..., ...  ; ...
...) CLASS SomeCLass
// Less secure ( and simple ) form of an '[less]safe' init method
// It is better not to call any object method/access/assign from
// inside the init method, if needed do this form the 'New()' method.
// From here on insert you own initialization code
// Process the parameters
   ..., ... 
   IF lParameterError
      TSTrace Warning "... parameter error ..."
      SELF:InvalidateObject( )
   END
// At this point all initialization code should be done
   IF SELF:IsValidObject
//    The 'New()' method will be called by the SUPER class
      SUPER:INIT( ... ; ...
     ... , ... )
   ELSE
      TSTrace Warning TS_TEXT_GEN_CAN_NOT_INITIALIZE
      SELF:InvalidateObject( )
   END
RETURN SELF

METHOD INIT( ..., ...  ; ...
...) CLASS SomeCLass
// Most secure ( and complex ) form of an 'safe' init method
// It is better not to call any object method/access/assign from
// inside the init method, if needed do this form the 'New()' method.
   DO CASE
   CASE SELF:IsInited
      TSTrace Warning "Can not re-init"
   CASE SELF:IsInInit
      SELF:CountInInit( TRUE )
//    From here on insert you own initialization code
//    Process the parameters
      ..., ... 
      IF lParameterError
         TSTrace Warning "... parameter error ..."
         SELF:InvalidateObject( )
      END
//    At this point all initialization code should be done
      SELF:CountInInit( FALSE )
      IF SELF:IsValidObject
         SUPER:INIT( ... ; ...
        ... , ... )
         IF SELF:NeedNew
            SELF:NeedNew:=FALSE
//          Put your 'PostInit()' code in the 'New()' method
            SELF:NEW( ... ; ...
           ... , ... )
         END
      ELSE
         TSTrace Warning TS_TEXT_GEN_CAN_NOT_INITIALIZE
         SELF:InvalidateObject( )
      END
   OTHERWISE
      TSTrace Warning "This can not happen"
   END
RETURN SELF

Source

METHOD INIT( uoOwner, usymNameSym, uloSelfDestruct ) CLASS TS_Root1
LOCAL cAccessTypeList AS STRING
LOCAL oOwner AS OBJECT
LOCAL lInit AS LOGIC
   TSTrace Enter CREATE
   IF LOGIC( _CAST, _AND( SELF:_ObjectStat1, TS_OBJSTAT1_ININIT  ; ...
  ... ) )
      SELF:_ObjectStat1+=TS_OBJSTAT1_COUNTVALUE
      cAccessTypeList:=TS_AccessTypeList( uoOwner, usymNameSym, uloSelfDestruct )
      lInit:=TRUE
      DO CASE
      CASE CharPos( cAccessTypeList, 1 )=="U"
         oOwner:=SELF:_Owner
      CASE CharPos( cAccessTypeList, 1 )=="O"
         oOwner:=uoOwner
      OTHERWISE
         lInit:=FALSE
      END
      DO CASE
      CASE CharPos( cAccessTypeList, 2 )=="U"
//       Do nothing
      CASE CharPos( cAccessTypeList, 2 )=="#"
//       Do nothing
      OTHERWISE
         lInit:=FALSE
      END
      DO CASE
      CASE CharPos( cAccessTypeList, 3 )=="U"
//       Do nothing
      CASE CharPos( cAccessTypeList, 3 )=="L"
//       Do nothing
      CASE CharPos( cAccessTypeList, 3 )=="O"
//       Do nothing
      OTHERWISE
         lInit:=FALSE
      END
      IF lInit
         IF IsAssign( SELF, #SelfDestructOnUnRegisterOwner )
            DO CASE
            CASE oOwner==NULL_OBJECT
               IVarPut( SELF, #SelfDestructOnUnRegisterOwner, FALSE )
            CASE CharPos( cAccessTypeList, 3 )=="L"
               IVarPut( SELF, #SelfDestructOnUnRegisterOwner, uloSelfDestruct )
            CASE CharPos( cAccessTypeList, 3 )=="O"
               DO CASE
               CASE Empty( uloSelfDestruct )
                  IF LOGIC( _CAST, _AND( SELF:_ObjectStat2, TS_OBJSTAT2_SELFDESTRUCT_ASSIGN  ; ...
                 ... ) )
//                   The application has set the 'SelfDestructOnUnRegisterOwner'  ; ...
//                  ... property
                  ELSE
                     IVarPut( SELF, #SelfDestructOnUnRegisterOwner, TRUE )
                  END
               CASE IsAccess( uloSelfDestruct, #SelfDestructOnUnRegisterOwner )
                  IVarPut( SELF, #SelfDestructOnUnRegisterOwner, IVarGet( uloSelfDestruct ; ...
                 ... , #SelfDestructOnUnRegisterOwner ) )
               OTHERWISE
                  TSTrace Warning "!IsAccess(uloSelfDestruct,#SelfDestructOnUnRegisterOwner)"
                  SELF:InvalidateObject( )
               END
            CASE LOGIC( _CAST, _AND( SELF:_ObjectStat2, TS_OBJSTAT2_SELFDESTRUCT_ASSIGN  ; ...
           ... ) )
//             The application has set the 'SelfDestructOnUnRegisterOwner' property ; ...
            OTHERWISE
               IVarPut( SELF, #SelfDestructOnUnRegisterOwner, TRUE )
            END
         END
         IF !SELF:IsInvalidated
            IF SELF:_Owneds==NULL_ARRAY
               SELF:_Owneds:=ArrayCreate( 0 )
            END
            SUPER:INIT( usymNameSym )
            IF SELF:IsInvalidated
               TSTrace Warning "SELF:IsInvalidated"
               SELF:InvalidateObject( )
            ELSE
               IF oOwner<>NULL_OBJECT
                  IF IsMethod( SELF, #RegisterOwner )
                     SELF:_ObjectStat2:=_OR( SELF:_ObjectStat2 ; ...
                    ... , TS_OBJSTAT2_REGISTER_ENABLED )
                     Send( SELF, #RegisterOwner, oOwner )
                  ELSE
                     SELF:_ObjectStat2:=_OR( SELF:_ObjectStat2 ; ...
                    ... , TS_OBJSTAT2_NOTREGISTERED )
                     SELF:_Owner:=oOwner
                  END
                  SELF:_ObjectStat2:=_OR( SELF:_ObjectStat2 ; ...
                 ... , TS_OBJSTAT2_REGISTER_DISABLED )
                  IF SELF:_Owner<>oOwner
                     TSTrace Warning "SELF:_Owner<>oOwner"
                     SELF:InvalidateObject( )
                  END
               END
            END
         END
      ELSE
         TSTrace Warning "Invalid parameter(s), Expected 'U|O', 'U|#' and 'U|L|O'" ; ...
        ... +", Found '"+cAccessTypeList+"'"
         SELF:InvalidateObject( )
      END
      SELF:_ObjectStat1-=TS_OBJSTAT1_COUNTVALUE
      IF _AND( SELF:_ObjectStat1, TS_OBJSTAT1_NEWTEST )==TS_OBJSTAT1_NEEDNEW
         SELF:_ObjectStat1:=_AND( SELF:_ObjectStat1 ; ...
        ... , _NOT( TS_OBJSTAT1_NEEDNEW ) )
         IF SELF:IsValidObject
            SELF:NEW( uoOwner, usymNameSym, uloSelfDestruct  ; ...
           ... )
         ELSE
            TSTrace Warning TS_TEXT_GEN_CAN_NOT_INITIALIZE
            SELF:InvalidateObject( )
         END
      END
   ELSE
      TSTrace Warning "!LOGIC(_CAST,_And(SELF:_ObjectStat1,TS_OBJECT_STATUS_ININIT))"
   END
   TSTrace Leave
RETURN SELF