XClasses.pas unit
This unit contains definition of the base class for all XCL objects
tree - XClass. It is a descender of TObject and only adds ability to become a parent and
to have childs of XClass type. Also it is using simple object ZList which is intended to
replace Delphi TList. ZList does not support of sorting, swapping of elements and it is
compiled to smaller code. ZList class also is defined in XClasses.pas unit.
All the other XCL classes are descending from XClass, so all those
inherit properties ChildCount and Children[ Idx ] and methods AddChild and DeleteChild
(but these last two usually not needed because the constructor of XClass is overridden and
have AParent : XClass parameter).
In contrast to VCL, where base class for all objects is TPersistent,
XCL objects do not provide ability of reading its original state from form definition,
stored in executable. This allow not to link stream support modules, input/output routines
needed to read data from executable and recognize it and do not store form definition
resources blocks in executable. As a result, application stays dramatically small. (So I
decided to call applications, created with XCL, as APPLETS
- not applications).
Disadvantage of this is only non-visual programming, which is
inconvenient for programmers because it is necessary now to place controls on forms only
at run time. Programming in XCL, at design time developer can now work only with pascal
code. No ObjectInspector, no double click on event to create event handler, no components
palette and so on. But all these is generously repaid by extremely small size of the final
application, and You do not ever need to distribute bpl- or dpl-files to deploy it!
XClass <= TObject
XClass properties:

Parent : XClass;

ChildCount : Integer;

Children[ Idx : Integer ] : XClass;
XClass methods:
constructor Create(
AParent : XClass );
- use it to create new XClass instance and to assign AParent to it as parent
XClass object (this will call method AddChild
for AParent to add newly created XClass instance as a child - if AParent is not nil) |
destructor Destroy;
- destructor first calls DeleteChild method for parent XClass object and then it
destroys children before call of inherited destructor. |
- procedure AddChild( Child : XClass ); virtual;
- usually You do not need call AddChild manually. When child created with AParent
parameter, procedure AddChild is called automatically for parent to add newly created
object as a child of it. |
- procedure DeleteChild( Child : XClass ); virtual;
- also do not call it usually. It is called for parent when child is destroying. |
ZList = class( TObject );
ZList properties:

Count : Integer;

Capacity : Integer;
Items[ Idx : Integer ] : Pointer;
ZList methods:
procedure Clear;
- procedure Dispose;
- useful in case when items of ZList are dynamically allocated. Dispose first
calls FreeMem for all items not equal to nil, and then calls Clear. |
function Add(
Value : Pointer ) : Integer;
- adding new item Value to the end of the list. |
function Insert(
Idx : Integer; Value : Pointer ) : Integer;
- inserting new item Value before item with index Idx (or to the end of list, if
Idx = Count). |
procedure Delete(
Idx : Integer );
- deleting item Idx with shifting follows item up. |
function IndexOf(
Value : Pointer ) : Integer;
- returns index of first occurance of Value in list or -1, if the list does not
contain such Value. |
Other definitions of XClasses.pas unit:
XOnEvent = procedure( Sender : TObject ) of
object;
- use it instead of TNotifyEvent type (usually for events, which has only one
parameter - sender of the event). It is intended here because TNotifyEvent is defined in
Classes.pas unit, which is not recommended to use in XCL because of too fast growing of
executable size. |
function XRect(
Left, Top, Right, Bottom ) : TRect;
- use it instead of VCL function Rect because this last is defined in Classes.pas. |
function XPoint(
X, Y : Integer ) : TPoint;
- use it instead of VCL function Point because this last is defined in
Classes.pas. |
- function RectsEqual( R1, R2 : TRect ) : Boolean;
- returns True, if R1 is equal to R2. |
- function PointInRect( P : TPoint; R : TRect ) : Boolean;
- returns True, if P is beloning to rect XRect( R.Left, R.Top, R.Right-1,
R.Bottom-1 ), i.e. strict inequalities are using to compare with Right and Bottom sides of
rectangle R. |
- function XMin( X, Y : Integer ) : Integer;
- returns minimal from values X and Y. |
- function XMax( X, Y : Integer ) : Integer;
- returns maximal from values X and Y. |
Also type XMethod declared here. It is very
similar to TMethod, defined in Classes.pas belonging to VCL, and can be used for the same
purposes (to access variables of type 'procedure of object').
Also class XChild
derived from XClass is defined here. It overrides AddChild
method to prevent adding children. Its purpose is to be ancestor of classes, which can be
children for XClass descending parents, but avoid to be parents itself (e.g., XTimer ).
Tasks.
Usually You have not to create instances and descend new classes
directly from XClass if You want to create visual elements (forms, controls). To create
new control, use XCustomControl or XMfcControl as a base. And to create new type of form use XForm as an ancestor. Type XClass is taking place at the root of
XCL hierarchy and You only have to know its properties and methods which are inheriting in
its descenders.
You can derive new class from XClass and its descenders (vs TObject) if
You want to destroy it automatically when its parent (descender of XClass too) is
destroyed. Nothing else. And this is similar for TComponent descenders in Delphi VCL.
Type ZList is useful and necessary in most programming tasks. And
You may use it as an ancestor of more complex lists (e.g. to add sorting ability to
these).
goto XCL page
goto home
page