Please enable JavaScript to view this site.

KOL/MCK - User Guide

TObj( unit KOL.pas ) _TObj

TObj = object( _TObj )

Prototype for all objects of KOL. All its methods are important to implement objects in a manner similar to Delphi TObject class.

 

 

TObj properties

 

property RefCount: Integer;

 

property Free: Integer;  

Before calling destructor of object, checks if passed pointer is not nil - similar what is done in VCL for TObject. It is ALWAYS recommended to use Free instead of Destroy - see also comments to RefInc, RefDec.

 

property Tag: DWORD;

Custom data field.

 

 

TObj methods

 

destructor Destroy; virtual;

Disposes memory, allocated to an object. Does not release huge strings, dynamic arrays and so on. Such memory should be freeing in overridden destructor.

 

procedure Final;

It is called in destructor to perform OnDestroy event call and to released objects, added to fAutoFree list.

 

procedure RefInc;

See comments below: RefDec.

 

function RefDec: Integer;

Decrements reference count. If it is becoming <0, and Free method was already called, object is (self-) destroyed. Otherwise, Free method does not destroy object, but only sets flag "Free was called".

Use RefInc..RefDec to provide a block of code, where object can not be destroyed by call of Free method. This makes code more safe from intersecting flows of processing, where some code want to destroy object, but others suppose that it is yet existing.

If You want to release object at the end of block RefInc..RefDec, do it immediately BEFORE call of last RefDec (to avoid situation, when object is released in result of RefDec, and attempt to destroy it follow leads to AV exception).

Actually, this "function" is a procedure and does not return any sensible value. It is declared as a function for internal needs (to avoid creating separate code for Free method)

 

function InstanceSize: Integer;

Returns a size of object instance.

 

constructor Create;

Constructor. Do not call it. Instead, use New<objectname> function call for certain object, e.g., NewLabel( AParent, 'caption' );

 

function AncestorOfObject( Obj: Pointer ): Boolean;

Is intended to replace 'is' operator, which is not applicable to objects.

 

function VmtAddr: Pointer;

Returns addres of virtual methods table of object.

 

procedure Add2AutoFree( Obj: PObj );

Adds an object to the list of objects, destroyed automatically when the object is destroyed. Do not add here child controls of the TControl (these are destroyed by another way). Only non-control objects, which are not destroyed automatically, should be added here.

 

procedure Add2AutoFreeEx( Proc: TObjectMethod );

Adds an event handler to the list of events, called in destructor. This method is mainly for internal use, and allows to auto-destroy VCL components, located on KOL form at design time (in MCK project).

 

procedure RemoveFromAutoFree( Obj: PObj );

Removes an object from auto-free list

 

procedure RemoveFromAutoFreeEx( Proc: TObjectMethod );

Removes a procedure from auto-free list

 

 

TObj events

 

property OnDestroy: TOnEvent;

This event is provided for any KOL object, so You can provide your own OnDestroy event for it.

 

 

TObj fields

 

fAutoFree: PList;  

Is called from a constructor to initialize created object instance filling its fields with 0. Can be overridden in descendant objects to add another initialization code there. (Main reason of intending is what constructors can not be virtual in poor objects).

 

fTag: DWORD;  

Custom data.

 

KOL / MCK User Guide - Created by Carl Peeraer - Diamant Soft, based on the work of Vladimir Kladov - Artwerp.be

  

Keyboard Navigation

F7 for caret browsing
Hold ALT and press letter

This Info: ALT+q
Nav Header: ALT+n
Page Header: ALT+h
Topic Header: ALT+t
Topic Body: ALT+b
Exit Menu/Up: ESC