CountInInit
(Available in 00 TS Tools(Base) - TS_Tools_Root0)
Purpose
Set/reset the 'IsInInit'-flag
Syntax
SELF:CountInInit( TRUE | FALSE )
Arguments
Description
One of the first things to do from the 'Init()' method is call this method with 'TRUE' as parameter. The objectstatus is updated and is used to deside when to call the 'New()' method of the object.
When the initialization of the object is finished then this method should be called with 'FALSE' as parameter. After this call the application code can deside to call the 'New()' method by cheking the 'SELF:NeedNew' flag. This method ensures that the object is only allowed to initialize once, and also that the 'New()' method is called once ( form the object highest in the class hirarchy ).
Note: Be sure that calls to this method are symetrical, be sure to first call 'SELF:CountInInit(TRUE)' and then 'SELF:CountInInit(TRUE)' never do the calls in reverse orden and never call this method from 'outside' de object ( e.g. always use SELF as the method sender ).
Hint: Cut and paste this example to be used in your application code.
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: