Attention: everything that is written in this application, starting from version 3.00, is no longer relevant at all - classes in KOL are no longer needed and are not supported. The main thing is that this mechanism existed, is available in the archives of the source codes of previous versions, and you can always resume it in case of urgent need.
In order for KOL projects to be successfully compiled by the Free Pascal compiler version 1.xx.xx, that is, even when this wonderful compiler did not support simple Object Pascal objects, a version of the KOL library code was specially "created" for this purpose.
I put "created" in quotation marks because, in fact, the second version of the same KOL.pas module was not created, it would be simply unimaginably difficult to constantly synchronize all changes in two such large modules (I do not always succeed in one all agree). At the same time, the use of constructions {$ IFDEF…}… {$ ELSE}… {$ ENDIF} to implement such a variation of the code, when in the case of adding any symbol of conditional compilation, it was also rejected. First, it would clutter up the source code, which is already difficult to understand. And secondly, it could have confused the Delphi IDE and could well have confused its Code Completion and Code Navigation subsystems.
As a result, a combined approach was chosen using a specially designed external preprocessor GLUECUT (this name has nothing to do with glitch, and is a combination of two English words "glue" and "cut"). This application can be used not only for the purpose of converting the KOL module (and related) into classes, but also for any other tasks of a similar nature that require a powerful text processor.
Why is the approach combined? The answer is that in the process of processing the text of the module, a set of rules is used to control the transformation of the input text into the output, which can change in different parts. Sections are set by "tags" in the source file, which are comments of the form // [...], located from the beginning of the line and occupying the entire line. The rules allow you to set the replacement of specified substrings, as well as manipulate whole strings. That is, the content of the input text is partially used, and some of the information about what and how to replace is in an external command file.
For example, if you have to write @ Self in KOL, because Self is the object itself, and you need a pointer to this object, then in the case of using classes, the @ sign should be eliminated, since the class instance variable itself is already a pointer. View rule
REPLACE [@Self] [Self]
- will perform all such replacements.
In addition, the rules allow you to bypass or replace specially marked sections of code, and in this case, short comments in curly braces are used as labels, for example, all sections {-} ... {+} when copying the source text into the output can be skipped by the rule
SKIP [{-}] [{+}]
In a sense, an analogue of conditional compilation is the opposite construction, which allows you to insert text for the future input variant for classes into the source code, but so that in the source code itself, this text will be a pure comment from the point of view of the Pascal compiler:
{++} (* TObj = class; *) {-}
Such a replacement is implemented in the command preprocessor language with a couple of rules
REPLACE [{++} (*] []
REPLACE [*) {-}] []
As you can see, everything is simple. A developer using an old version of the Free Pascal compiler, or simply preferring classes, having received (downloaded, updated) a new version of the KOL.pas file, simply runs a bat file that calls the GLUECUT utility with the required parameters, and as a result, a KOL version with classes.
Finally, I will add that, starting from version 2.10, the Free Pascal compiler fully supports simple Object Pascal objects, and there is no longer a special need for converting KOL to classes. Nevertheless, using classes for some purpose may still be useful to someone, so I felt it necessary to provide information about this possibility.