InvalidateObject

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

Purpose

Invalidate the object

Syntax

SELF:InvalidateObject( )

Description

Invalidates the object, this method is normaly only called from the 'Init()' method of the object. When this method is called then the destroy method could take extra care while destroying resources knowing the the object never reached a 'valid' state.

Example

METHOD INIT( ..., ...  ; ...
...) CLASS SomeClass
// Most secure ( and complex ) form of an 'safe' init method
// See also the 'Init()' method documentation
   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
//    It is better not to call any object method/access/assign
//    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 InvalidateObject( ) AS OBJECT PASCAL CLASS TS_Root0
   TSTrace Enter
   SELF:_ObjectStat1:=_AND( SELF:_ObjectStat1 ; ...
  ... , _NOT( TS_OBJSTAT1_NEEDNEW ) )
   SELF:_ObjectStat1:=_OR( SELF:_ObjectStat1 ; ...
  ... , TS_OBJSTAT1_INVALID )
   SELF:_ObjectStat2:=_OR( SELF:_ObjectStat2 ; ...
  ... , TS_OBJSTAT2_SELFDESTRUCT_FREEZE )
   IF !LOGIC( _CAST, _AND( SELF:_ObjectStat1, TS_OBJSTAT1_DISALLOWEDESTROY  ; ...
  ... ) )
      SELF:_ObjectStat1:=_OR( SELF:_ObjectStat1 ; ...
     ... , TS_OBJSTAT1_DESTROYREQUESTED )
      TSTrace Warning Debug "Invalidate-object granted, Object will be destroyed"
      SELF:Destroy( )
   ELSE
      TSTrace Warning Debug "Invalidate-object granted, Object destroyed earlier"
   END
   TSTrace Leave
RETURN SELF