Please enable JavaScript to view this site.

KOL/MCK - User Guide

Oh, how many wonderful discoveries we have

Prepares the spirit of enlightenment!

And experience, son of difficult mistakes,

And a genius, a friend of paradoxes,

And chance, Fortune's half-brother.

(A.S. Pushkin)

 

Now that you've got the initial idea of ​​the capabilities of forms, applets and - in general - other visual elements, it's time to talk a little about the development of MCK projects. The ability to create an MCK project, toss a couple of MCK components onto a form, configure them and launch the project will allow the reader, upon further reading, to feel what he has read through experience. For, as experience shows, there is no better way to learn than ... experience.

As already mentioned at the beginning of the presentation, the Mirror Classes Kit, i.e. a set of mirrored components for the KOL library did not appear immediately. The ideology of the KOL library denies the very possibility of using components, i.e. classes derived from TComponent, classes that could exist both at the stage of development and at the stage of application execution (in the second case, loading its initial state from the resources of the form, during its construction). This is how the Delphi environment works, and I must admit, this is a very convenient approach that significantly speeds up application development, and it is not for nothing that Delphi is proudly called RAD - Rapid Develpment Tool, or, translated into Russian: rapid development tool.

Nevertheless, KOL managed to build a not the worst mechanism for visual programming. MCK contains a set of mirror components (or simply - mirrors), roughly corresponding to the set of varieties of simple KOL objects. In the same way as in the development of a VCL project, these mirrors are thrown onto the form from the component ruler, their properties are configured visually (with the mouse, the Object Inspector, calling special component editors). And as a result of the joint work of these components at the development stage, the text of the source files of the projects is modified in such a way that, when compiled, we get a "clean" KOL project, in which there are no classes, components, and other references to VCL, but only simple objects object, and a minimum of code with all the necessary functionality.

Perhaps it is worth highlighting this feature, and emphasizing once again that MCK components do not participate in the working version of the code. Their task is only to generate code for KOL, which is placed mainly in inc files, and when the application is executed, it is called to create the form along with all its children. That is, the form at run time does not create itself from the form resource, as is done in a VCL application, but is built dynamically by calling the appropriate NewXXXX functions, assigning initial values ​​to properties and events in accordance with the settings of MCK components made at the design stage. ...

 

In fact, the MCK idea is not so trivial. The mirrored component code contains a number of tricks designed to "trick" the development environment. As a result, the Delphi IDE thinks that it is dealing with a regular VCL project with classes and forms loaded from dfm resources, although this is far from the case.

 

 

pointing-up-finger

Creating an MCK project starts with the same thing as creating a VCL project, namely: in the File menu of the development environment, select the New Application item. As a result, the project Project1 is created, containing three files (so far they are stored in memory): this is Project1.dpr - the source file of the project, Unit1.pas - the source file of the only form module so far, and Unit1.dfm - the form file. The next step that now needs to be done is to save the project in a folder. To do this, we select File | Save All in the menu, and we are sequentially prompted to save Projec1.dpr and Unit1.pas (the Unit1.dfm file is saved automatically in the same folder where the Unit1.pas file is also saved). When saving, it is worth changing the name of the Unit1.pas module (unless you intend to leave this name forever: Renaming modules in an MCK project can be a bit tricky, so it's best to think about module names in advance). However, you should not change the name of the project for now, let it remain Project1 (below I will explain why).

Another important point: keep all source files of the MCK project (at least the form modules and the project file itself) in one directory. If you put them in different folders, MCK may not be able to detect them and make the necessary modifications.

 

Now that the project has been saved, we begin to "convert" it to an MCK project. At this point, the MirrorKOLPackageXX package for the corresponding Delphi version should already be installed. Since I work with MCK components most of the time, after installing this package, I immediately go to the Component | Configure Palette menu and drag this set of components closer to the beginning, so as not to scroll through all the palette tabs in a row.

 

Conversion consists of four very simple steps. But they must be executed exactly, otherwise question # 1: "why is KOL / MCK not installed?" - is inevitable. Make your life easier, read the instructions very carefully !.

 

 

TKOLProject component

 

Firstly, you need to find it on the component ruler in the KOL tab and drop the TKOLProject component onto the form.

 

One such component must always be present in an MCK project. By the way, you shouldn't use Delphi's ability to open more than one project at the same time. As soon as two TKOLProject components are loaded simultaneously, they will start loudly complaining about the inadmissibility of the situation that has arisen.

 

When the TKOLProject component is created for the first time, or when opening an MCK project, it "comes to life" and starts checking regularly (by timer, the checking period is regulated by the autoBuildDelay property - in milliseconds) whether MCK components have requested code regeneration due to changing a property in any MCK mirror (including in the TKOLProject component itself). As soon as such a change is committed, by the next event from its timer, all forms of the project are searched for, and for those that have changed, a code regeneration is called, and, if necessary, a new version of the code for the project itself is generated.

 

clip0002

 

 

TKOLProject component - projectDest property

 

Secondly, you must now select the TKOLProject component on the form, switch to the Objects Inspector (F11 key), find and change the projectDest property. Enter the "real" name of the project in this field, other than Project1. For example, test1 is a perfectly valid name for a test project. (The project is ready for conversion, there is only a small step left to do).

 

 

TKOLForm component

 

Thirdly, find on the ruler, also in the KOL tab, the TKOLForm component, and also drop it on the form. Didn't you notice anything? In vain: you need to look carefully. If you had looked at the source code of the module before you dropped that component on the form, and compared it with what happened after that, you would have noticed that there were quite a lot of changes. But more on that later. There is one more step to take.

 

A number of changes are made to the code to ensure (through conditional compilation directives) that the compiler is invisible to the code that should not be compiled. At the same time (fortunately for MCK) the Delphi IDE itself "does not notice" the conditional compilation directives, which make undesirable code fragments invisible to the compiler. As a result, the form file, mirrored components, and form declaration text remain "visible" to the Object Inspector and the IDE, which continues to treat the project as a normal VCL project. In particular, even the Code Completion tools continue to work, and the navigation tools between methods and their declarations in a fictitious form class from now on continue to work. At least up to and including Delphi 2010.

In addition, the {$ INCLUDE ...} directive is added to link to the newly created file <module_name> _1.inc, which contains the procedure for initializing the form New <form_type_name> (Form_Var, Aparent).

 

clip0003

 

 

Save the MCK Project

 

 

pointing-up-finger

Fourth, you need to save the result (File | Save all), and close the project. Why close? Because now in Delphi, the loaded is not the MCK project that we created as a result of the previous four steps, but a VCL project named Project1. We now need to open our project. "Test1" seems to be what we called it, right? Not? Well, you know better.

In principle, you can not close the project, but immediately select the File | Open Project menu item, and select the test1.dpr file for loading (well, or whatever you called it there). Moreover, at this moment I usually still pre-select the Project1.dpr file in the open dialog and press the <Delete> button - this file will no longer be needed (as the great Shakespeare said, "the Moor has done his job, the Moor can leave").

 

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