Wiki copymirror

This is a mirror of the wiki at pascal.chat. Editing, history and sign-in are there.

KOL

Introduction

kolmck.png

The Key Objects Library, a.k.a. KOL, is an object oriented framework created by Vladimir Kladov in 2000. It is the successor to the XCL library by the same author. The Mirror Classes Kit, a.k.a. MCK, is a set of visual components to write KOL applications in a visual design way, from within the Delphi IDE.

The current point release is 3.23 for KOL and 3.23 for MCK.

New versions appear with Irregular intervals, but the library is currently maintained.
There is a git repository for KOL and MCK at https://github.com/Thaddy/kol4/ which is usually more up to date than the point releases. At the time of writing this is version 4.00RC and updated to work with newer Freepascal and Delphi versions.

The main reason creating this library is explained through the dissatisfaction of Vladimir and others towards ever increasing code bloat. Nobody seemed to care anymore about efficient coding. According to KOL users there a strong correlation between Moore's law and degrading code optimizing efficiency.

An MCK project designed in a Delphi IDE can be recompiled with both 32 bit and 64 bit FPC 2.7.1 or later compilers without change. This way you can without having to upgrade your Delphi to a recent version:

The framework centers around three basic concepts:

This has several advantages , some of which are:

It also has very obvious disadvantages , some of which are:

Requirements

Supported targets

Example

Let's illustrate KOL with a simple example. A form, a button and some action. You will notice that the code resembles that of a LCL/VCL application and basically: It does exactly the same! The main difference is the use of objects and pointer to objects instead of classes and the use of constructing functions instead of constructors.

Here's the main program file:

pascal
program koldemo;
     {This line makes us FPC and Delphi compatible}
     {$IFDEF FPC}{$MODE DELPHI}{$H+}{$ENDIF}
     {$APPTYPE GUI}
     uses
      Kol,
      koldemo1 in 'koldemo1.pas';
     
     begin
      NewForm1( Form1, nil);
      Run(Form1.form);
     end.

And here is the main unit, again, you will notice it is very similar to LCL/VCL code:

pascal
unit koldemo1;
     
     interface
     uses
       Windows, Messages, Kol;
     const
      cps:KolString = 'Kol project in ' + {$IFDEF FPC}'Freepascal '{$ELSE}'Delphi '{$ENDIF} +
         {$IFDEF WIN64}'64 bits '{$ELSE}'32 bits '{$ENDIF} +
         {$IFDEF UNICODE_CTRLS}'Unicode'{$ELSE}'Ansi'{$ENDIF};
     type
     
     PForm1=^TForm1;
     TForm1=object(Tobj)
       {Note both widgets are of the same type}
       Form, Button:pControl;
     public
       {The message handler for our Button}
       procedure ButtonClick(Sender:PObj); 
     end;
     
     procedure NewForm1( var Result: PForm1; AParent: PControl );
     
     var
       Form1:pForm1;
     
     implementation
     
     procedure NewForm1( var Result: PForm1; AParent: PControl );
     begin
       New(Result,Create);
       with Result^ do
       begin
         {The appearance of a widget depends on its creating function}
         Form := NewForm(AParent,cps);
         Button := NewButton(Form,'&Click Me');
         {Attach the MessageHandler}
         Button.OnClick := ButtonClick;
         { The applet variable is the Application object
           Assigning the main form to it assigns the main message loop to the form.}
         Applet:=Form;
         Form.Add2AutoFree(Result);
       end;
     end;
     
     procedure TForm1.ButtonClick(Sender: PObj);
     begin
        ShowMessage('Ouch!');
     end;
     
     end.

So what's so special about it? Well, for one, compile this and look at the executable size. A similar program, Form + Button + ShowMessage compiled with Delphi 7 is 394 Kilobytes and it gets much worse for progressive newer versions of Delphi:2267 Kilobytes XE7-32, 3672 Kilobytes XE7-64. For comparison: the KOL version compiled with D7 is 156 times smaller than the VCL version compiled with XE7.

Compiled with PPC386 it renders an executable of 48128 bytes. Compiled like:

pascal
ppc386 -Mdelphi -CX -XX -Xs -Os koldemo.dpr

Compiled with PPCX64 for Windows it renders 65536 bytes. Compiled like:

pascal
ppcx64 -Mdelphi -Rintel -CX -XX -Xs -Os koldemo.dpr

The above examples are for an ANSI application. To compile a UNICODE application, simply add the UNICODE_CTRLS define, like:

pascal
ppcx64 -Mdelphi -Rintel -dUNICODE_CTRLS -CX -XX -Xs -Os koldemo.dpr

Note that especially for 64 bit, Free Pascal renders consistently smaller code than its expensive cousin. Also note that 32 bit Free Pascal has a slightly bigger runtime payload than its cousin. The size difference disappears when your application becomes more complex.

Tip

For size, KOL defaults to an ugly system font. Here are multiple ways to remedy that:

pascal
{Add this code after the NewForm Function}
     {Release the font}
     Form.Font.ReleaseHandle;
     {Assign the default windows GUI font object}
     Form.Font.AssignHandle(GetStockObject(DEFAULT_GUI_FONT));

The second method is slightly more involved, but is the |MSDN recommended way:

pascal
{Add this function}
     function GetGuiFont:TLogFont;
     var Metrics:TNonClientMetrics;
     begin
       Metrics.cbSize := SizeOf(Metrics);
       SystemParametersInfo(SPI_GETNONCLIENTMETRICS, SizeOf(Metrics), @Metrics, 0);
       Result := Metrics.lfMessageFont;
     end;
     {And call it after the form creation}
     Form.Font.LogFontStruct :=GetGuiFont;

Fonts in KOL are objects of type TGraphicTool. This object can also represent pens and brushes. We can also create a new GraphicTool object representing the GUI font:

pascal
{The KOL way to assign the GUI font}
     function GuiFont:PGraphicTool;
     var Metrics:TNonClientMetrics;
     begin
       Result := NewFont;
       Metrics.cbSize := SizeOf(Metrics);
       SystemParametersInfo(SPI_GETNONCLIENTMETRICS, SizeOf(Metrics), @Metrics, 0);
       Result.LogFontStruct := Metrics.lfMessageFont;
     end;
     {We can now assign the new font to the Form's font property}
     Form.Font.Assign(GuiFont);

And this is the result: kolscreenshot.png


From the Free Pascal wiki, page "KOL", as the Internet Archive kept it on 2026-08-06, last changed on 2026-07-17. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 4, last changed by WikiArchive .