initial commit
[rofl0r-KOL.git] / KOLmirrorReadme.txt
blob387d6cd1d80a35d9051b35ffc71d849f90ed758b
1 Mirror Classes Kit for Key Objects Library, v2.00 [15-Nov-2004]\r
2 Copyright (C) 1999, 2000-2003 by Vladimir Kladov\r
3 -------------------------------------------------\r
4 Delphi 2, 3, 4, 5, 6, 7 are supported.\r
5 Compatible with Free Pascal 1.0.5 / 1.0.6 and higher\r
6 Partially compatible with Kylix (to compile projects for Linux/Qt)\r
7 \r
8 PLEASE, READ CAREFULLY THE *WARNINGS* AT THE END OF THIS FILE !\r
9 \r
10         CONTENTS\r
12    I. INTRODUCTION\r
13   II. INSTALLATION INSTRUCTIONS\r
14  III. STARTING NEW KOL MIRROR PROJECT\r
15   IV. ADDING A FORM\r
16    V. REMOVING A FORM\r
17   VI. RENAMING A FORM \r
18  VII. WRITING MIRROR CODE\r
19 VIII. ADDING REFERENCES TO A UNIT\r
20   IX. USING TComponent DESCENDANT FROM VCL\r
21    X. FILES CREATED AUTOMATICALLY\r
22   XI. MAINTAINANCE\r
23  XII. W A R N I N I N G S\r
24 XIII. RESOLVING PROBLEMS\r
26         I. INTRODUCTION\r
28 MCK is a kit of mirror classes for the VISUAL project development in Delphi environment using KOL library. (I will not explain here what is the KOL - refer on http://xcl.cjb.net). Though from the beginning nor KOL, nor its predecessor XCL were not fit and intended for the visual development, therefore offers, ideas, questions and thoughts from many people on this cause enterred with the enviable regularity. Finally, after some thoughts, I come to a conclusion that it is possible for KOL to make it visual. And, in spite of the collapse of preceding attempt (project XCL Wizard, if who in the course - it has deprived more than half a year beside me), I decided to start the new project on. And though I myself repeatedly convinced my opponents that it's impossible... For four evenings to me, it seems to jerk it.\r
30 Essence of idea of "mirror classes" is concluded in following. For each visually isolated object of KOL library Delphi VCL component is created, which is registerred by usual way for Delphi components and it is placed on the palette of components. I use the term "visually isolated object" because the same (from formal standpoints) object type in KOL can implement of different visual elements. For instance, TControl can be either form, or button, or label, or any other dialogue element.\r
32 Designing of project in "mirror" classes consists in following two steps:\r
33 - Placing two components TKOLProject and TKOLForm on the form, and running project first time to convert it into KOL-compliant. - When working with it at the design time as with usual VCL project, and when it is compiled, KOL objects are substituting corresponent mirror VCL objects, and application is very small.\r
35 +++++++++++++++++++++++++++++++++++++++++++++++++++\r
36 ++++++ The main difference of designing project for KOL using MCK from VCL are follows:\r
38 - You should not change properties of the form itself, excluding changing its size and position at design time. Change properties of TKOLForm component on it instead. Also, do not create events for a form itself, create events for TKOLForm component on it instead.\r
40 - You should not drop any non-MCK components and controls onto the form. Use only special MCK components designed for working with KOL project.\r
42 - Some of properties of MCK components are for design time only and such properties are not available at run-time. The most of such properties are named with small letters.\r
44 - To resolve a conflict between "Self" in VCL and "@Self" in KOL (which means the same), special word "Form" is introduced. It is implemented as a property, which returns at run-time pointer to a form (of type PControl), and is understanded at design time by Delphi compiler as a synonim of Self.\r
45    Always use this word in event handlers, created at design time, as a substitute of pointer to a form. Do not write \r
46         Caption := 'Hello!';\r
47 Write instead:\r
48         Form.Caption := 'Hello!';\r
49 Therefore, controls and objects, placed onto form at design time, are available by the same way like in VCL. If You write \r
50         Button1.Click;\r
51 this will be interpreted as usual.\r
53 - painting of "mirror" controls at design-time now implemented schematic, but later it is possible to detailizy painiting, overriding Paint method of TKOLControl descendants. (Moreover, it is possible to switch between two painting methods by checking special property of TKOLProject component and to get other advantages - now not implemented yet).\r
55 +++++++++++++++++++++++++++++++++++++++++++++++++++\r
56 ++++++ All other notes are the same as for programming with KOL non-visually.\r
58 - Do not inherit your own descendants from TControl. If You want to change message processing for certain control (or form, or Applet object), use events (and the most power is OnMessage, which allows to filter all messages, passed to a control), or attach external handler (using AttachProc method).\r
60 - If You want to create quit different (new) object, not presented in KOL, inherit it from TObj object.\r
62 - it is offerred to solve possible conflicts between the alike name of types, procedures, functions, constants and variable in KOL and VCL on the following rule: 1. if name has same that on the sense a type, conflict does not appear. 2. if only names coincide, the accompaniment prefix <KOL.> will resolve a conflict completely (reference to KOL must be added in the uses clause FIRST that KOL declarations have a smaller priority in contrast with VCL declarations  while code development at design time).\r
64 -------------------------------------------------------------------\r
65 See also Instructions below.\r
67         II. INSTALLATION INSTRUCTIONS\r
69 ______________________\r
70 DELPHI7 - INSTALLATION\r
72 1. Unpack files to the same folder, where You have KOL installed.\r
73 2. Open MirrorKOLPackageD7.dpk in Delphi IDE and click 'Install'.\r
75 DELPHI7 - UPGRADING\r
77 1. Close all files in IDE: File|Close All\r
78 2. Unpack files to the same folder, where You have KOL installed.\r
79 3. Open MirrorKOLPackageD7.dpk in Delphi IDE and click 'Compile' (Button 'Install' is not available, since package is installed).\r
80 ______________________\r
81 DELPHI6 - INSTALLATION\r
83 1. Unpack files to the same folder, where You have KOL installed.\r
84 2. Open MirrorKOLPackageD6.dpk in Delphi IDE and click 'Install'.\r
86 DELPHI6 - UPGRADING\r
88 1. Close all files in IDE: File|Close All\r
89 2. Unpack files to the same folder, where You have KOL installed.\r
90 3. Open MirrorKOLPackageD6.dpk in Delphi IDE and click 'Compile' (Button 'Install' is not available, since package is installed).\r
91 ______________________\r
92 DELPHI5 - INSTALLATION\r
94 1. Unpack files to the same folder, where You have KOL installed.\r
95 2. Open MirrorKOLPackage.dpk in Delphi IDE and click 'Install'.\r
97 DELPHI5 - UPGRADING\r
99 1. Close all files in IDE: File|Close All\r
100 2. Unpack files to the same folder, where You have KOL installed.\r
101 3. Open MirrorKOLPackage.dpk in Delphi IDE and click 'Compile' (Button 'Install' is not available, since package is installed).\r
102 ______________________\r
103 DELPHI4 - INSTALLATION\r
105 1. Unpack files to the same folder, where You have KOL installed.\r
106 2. Open MirrorKOLPackageD4.dpk in Delphi IDE and click 'Install'.\r
108 DELPHI4 - UPGRADING\r
110 1. Close all files in IDE: File|Close All\r
111 2. Unpack files to the same folder, where You have KOL installed.\r
112 3. Open MirrorKOLPackageD4.dpk in Delphi IDE and click 'Compile' (Button 'Install' is not available, since package is installed).\r
114 ______________________\r
115 DELPHI3 - INSTALLATION\r
117 1. Unpack files to the same folder, where You have KOL installed.\r
118 2. Open MirrorKOLPackageD3.dpk in Delphi IDE and click 'Install'.\r
120 DELPHI3 - UPGRADING\r
122 1. Close all files in IDE: File|Close All\r
123 2. Unpack files to the same folder, where You have KOL installed.\r
124 3. Open MirrorKOLPackageD3.dpk in Delphi IDE and click 'Compile' (Button 'Install' is not available, since package is installed).\r
126 ______________________\r
127 DELPHI2 - INSTALLATION\r
129 1. Unpack files to the same folder, where You have KOL installed.\r
130 2. Component|Install...|Add|Browse|mirror.pas|OK\r
131 3. Component|Install...|Add|Browse|mckObjs.pas|OK\r
132 4. Component|Install...|Add|Browse|mckCtrls.pas|OK\r
134 DELPHI2 - UPGRADING\r
136 1. Close all files in IDE: File|Close All\r
137 2. Unpack files to the same folder, where You have KOL installed.\r
138 3. Component|Install...|OK (earlier installed units mirror, mckObjs, mckCtrls should be seen already in a list)\r
141                                        *\r
142                                 *************** \r
143                         *******************************\r
145                      III. STARTING NEW KOL MIRROR PROJECT\r
147                         *******************************\r
148                                 ***************\r
149                                        *\r
151 1. Start Delphi and choose File|New Application.\r
153 2. DO NOT place any components on the form at this stage. Choose File|Save All and select the destination folder for your project. Note that ALL FILES of your project ALWAYS HAVE TO BE PLACED IN THE SAME DIRECTORY!\r
154 You may change the name of the .PAS file, but you MUST NOT change the name of the .DPR file.\r
156 3. Place the TKOLProject component onto the form.\r
158 4. The name of the output MCK file can be set by changing the ProjectDest property (path MUST NOT be included). If you type MySuperKOLProj, for instance, then the output MCK project will be named MySuperKOLProj.DPR. The EXE file's name will be (as you might have guessed already) MySuperKOLProj.EXE.\r
160 5. Drop the TKOLForm component onto the form.\r
162 6. In DELPHI5 only: Project | Options | Directories/Conditionals | Search path, add:\r
163    $(Delphi)\Source\ToolsApi\r
164    (this only seems to be necessary when working with Delphi 5 - the compiler needs to know the path to toolintf.pas, dsgnintf.pas, editintf.pas and exptintf)\r
166 7. If TKOLForm component was dropped (5.) AFTER changing ProjectDest property of TKOLProject component (4.), this step is not necessary, and destination project is ready. Otherwise:\r
167    change any property of the TKOLForm (or change the form's size or position). Even though no exe-file is created, you can open the resulting project immediately. This way allows you to convert a dll-project to a mck-compatible one as well.\r
169 8. Open the resulting project (it should be found in the same directory). Now it is high time you removed Project1.* - these files are no longer necessary.\r
171 9. Play with your new KOL/MCK Project (adjust Parameters, drop TKOL... components, compile, run, debug, etc.) Enjoy!\r
174         IV. ADDING A FORM\r
175 1. File|New form\r
176 2. Save it IN THE SAME directory where project is located.\r
177 3. Drop TKOLForm object onto it.\r
178 4. Be sure that You have TKOLApplet component dropped on the main form.\r
179 5. If AutoBuild is turned off: select TKOLProject component in main form and double click its property Build. (Otherwise, all should be done already, isn't it?)\r
180 Answer Yes to all questions about reload changed files (if any).\r
182         V. REMOVING A FORM\r
183 1. Project|Remove from project... as usual.\r
184 2. Select TKOLProject, double click Build property. (Than OK, ... - if any).\r
186         VI. RENAMING A FORM\r
188 Do not rename form itself, instead change FormName property of TKOLForm component on a form. Remember, that main form (with TKOLProject component on it also must be opened in the designer).\r
190         VII. WRITING MIRROR CODE\r
191   \r
192   Do not use names from VCL, especially from SysUtils, Classes, Forms, etc. All what You need, You should find in KOL.pas, Windows.pas, Messages.pas, ShellAPI.pas. And may be, write by yourself (or copy from another sources).\r
193   When You write code in mirror project - usually place it in event handlers.\r
194   You also can add any code where You wish but avoid changing first section of your mirror VCL form class declaration. And do not change auto-generated inc-files (marked as read-only by default).\r
195   Always remember, that code, that You write in mirror project, must be accepted both by VCL and KOL. By VCL - at the stage of compiling mirror project (and this is necessary, because otherwise converting mirror project to reflected KOL project will not be possible). And by KOL - at the stage of compiling written code in KOL namespace.\r
197   THIS IS IMPORTANT:\r
198   To resolve conflict between words VCL.Self and KOL.@Self, which are interpreted differently in KOL and VCL, special field is introduced - Form. In VCL, Form property of TKOLForm component "returns" Self, i.e. form object itself. And in KOL, Form:PControl is a field of object, containing resulting form object. Since this, it is correctly to change form's properties in following way: \r
199         Form.Caption := 'Hello!'; \r
200   (Though old-style operator Caption := 'Hello!'; is compiled normally while converting mirror project to KOL, it will be wrong in KOL environment).\r
201   But discussed above word Form is only to access form's properties - not its child controls. You access child controls and form event handlers by usual way. e.g.: \r
202         Button1.Caption := 'OK';\r
203         Button1Click( Form );\r
204   END OF IMPORTANT PARAGRAPH.\r
206   It is possible to create several instances of the same form at run-time. And at least, it is possible to make form not AutoCreate, and create it programmatically when needed. Use global function NewForm1 (replacing Form1 with your mirror form name), for instance:\r
207   TempForm1 := NewForm1( Applet );\r
208   To make this possible, NEVER access global variable created in the unit during conversation, unless You know why You are doing so. Refer to Form variable instead.\r
210         VIII. ADDING REFERENCES TO A UNIT\r
212   If You want to add a reference to another psacal unit in uses clause of your form unit, insert it as follows:\r
214 ====== CUT FROM TYPICAL UNIT WITH KOL FORM: ========\r
215 { KOL MCK } // Do not remove this line!\r
216 {$DEFINE KOL_MCK}\r
217 unit Unit1;\r
219 interface\r
221 {$IFDEF KOL_MCK}\r
222 uses Windows, Messages, ShellAPI, KOL {$IFNDEF KOL_MCK}, mirror, Classes,\r
223   Controls, mckCtrls {$ENDIF}, <-- list of your unit names here -->;\r
224 {$ELSE}\r
225 {$I uses.inc} mirror,\r
226   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,\r
227   mirror;\r
228 {$ENDIF}\r
229 ====== END OF CUT HERE ======\r
231         IX. USING TComponent DESCENDANT FROM VCL\r
233   Starting from MCK v0.71, it is possible to drop usual VCL-based components onto MCK form, and a code will be generated for proper creation and destructing these components. Please note, that therefore, using VCL-based components in KOL-MCK projects is not a good practice, because a lot of code which is not actually needed will be added to the executable.\r
234   However, using of visual VCL components in MCK projects is not possible at all. Moreover, TKOLProject and TKOLForm components are immediately locked, when any such VCL control is found on form. This prevents its from functioning, but avoids any damage due erroneous dropping MCK components onto forms of normal VCL project.\r
235   If VCL component is used in your MCK project, please note:\r
236 - automatic code generation is not occur even if Autobuild is set to True in TKOLProject. Double click TKOLProject component (e.g.) to force code generation after You change some properties / assign events to the component.\r
237 - when You drop the component onto MCK form at design time, Delphi adds a reference to its unit in uses clause of the form unit, but it is placed (usually) between {$IFNDEF KOL_MCK}...{$ENDIF} brackets, so the project can not be compiled. To correct this, go to the beginning of the unit, and move the reference to newly added unit as follows:\r
238    ..., SomeUnit {$ENDIF};      ->    ... {$ENDIF} , SomeUnit;\r
241         X. FILES CREATED AUTOMATICALLY\r
243 1. In addition to <YourProject>.dpr, following files are generated:\r
244    - <YourProject>_0.inc - contains alternative application initialization code.\r
245                                 Such code is running at run time instead of those generated\r
246                                 by standard auto-completion between 'begin' and 'end'\r
247                                 statements in dpr-file of the project. Structure is follows:\r
249                                 Applet := NewApplet( ... ); // if TKOLApplet is used only\r
250                                 [ Applet.Visible := False; ] // optional\r
251                                 [ Applet.OnMessage := ...; ] // optional\r
253                                 {$I <YourProject>_1.inc\r
254                                 {$I <YourProject>_2.inc // automatic, form creation\r
255                                 {$I <YourProject>_3.inc\r
257                                 Run( ... );\r
259                                 {$I <YourProject>_4.inc\r
261    - <YourProject>_1.inc - generated empty, if does not exist. You can alter it,\r
262                                 placing here code, which executed at run time after Applet\r
263                                 initialization. For instance, You can write here conditional\r
264                                 operator 'if' to prevent further running of application\r
265                                 in some cases.\r
267    - <YourProject>_2.inc - generated automatically, contains code to initializy\r
268                                 auto-created forms. You should never alter it.\r
270    - <YourProject>_3.inc and <YourProject>_4.inc - like for <YourProject>_1.inc, it is generated empty only if it does not exist. Place here your code You wish.\r
273 2. For every unit with form, additional file <UnitName>_1.inc is generated automatically. You should never change it manually.\r
275 3. File uses.inc also is generated automatically and You should not alter it manually. It contains word 'uses' only, included to final code via directive {$I uses.inc}. \r
277         XI. MAINTAINANCE\r
278   For backup / copy purposes, following files are necessary to be stored to restore your project later or in another directory (on another PC):\r
279   <YourProject>.dpr\r
280   <YourProject>_1.dpr - if You altered it\r
281   <YourProject>_3.dpr - if You altered it\r
282   <YourProject>_4.dpr - if You altered it\r
283   <YourProject>.res   - if You use app icon and altered it\r
284   <YourUnit>.pas      - for every unit\r
285   <YourUnit>.dfm      - for every unit with form\r
286   <YourProject>.cfg\r
287   <YourProject>.dof\r
288   other files, created specially for a project (*.rc;*.res;*.bmp;*.ico; etc.)\r
290 Files could be recreated, but desired for backup / copy:\r
291   <YourProject>_0.inc\r
292   <YourProject>_2.inc\r
293   <YourUnit>_1.inc    - for every unit\r
294   <YourProject>.dsk\r
295   <YourProject>.drc\r
297 And following files You are free to remove any time You wish:\r
298   *.dcu; *.~*; *.$$$; *.exe [ :) ]\r
300         ##############################\r
301         #                            #\r
302 #########  XII. W A R N I N I N G S  ###########\r
303         #                            #\r
304         ##############################\r
306 1. Never drop TKOLProject (and other KOL mirror components) on a form of normal VCL project. Never drop VCL controls onto MCK forms (though non-visual components are allowed). In both cases TKOLForm / TKOLProject components become locked and not functioning. To unlock these, You should first remove all VCL controls from the form, and then change Locked property to False for locked component(s).\r
307 2. Do not touch in converted project units all between automatically generated {$IF[N]DEF}...{$ENDIF}.\r
308 3. Don't edit automatically generated inc-files.\r
309 4. If You turned on console (property TKOLProject.ConsoleOut), NEVER CLOSE it. Instead, assign False to this property again.\r
310 5. Store mirror KOL projects at least in other folder(s), than usual VCL projects.\r
311 6. If anything will be damaged on Your computer, remember, that author of this software IS NOT RESPONSIBLE for such loss IN ANY WAY.\r
313         XIII. RESOLVING PROBLEMS\r
315 1. If you had no success installing MCK, read INSATALLATION INSTRUCTIONS carefully. E.g., take in attention, what package you install: may be, you have another Delphi version.\r
316 2. There are no problem with installing MCK in Delphi, no matter, what Delphi edition you use (e.g., Enterprise or Personal). You still have problems? Read instruction, please.\r
317 3. If you receive a message what ToolsApi or DsgnIntf not found, some syntax errors are found (though you did not yet write any code) or something similar occur: please read section "STARTING NEW KOL MIRROR PROJECT" carefully once again. May be, the reason is that you try to compile and run source project, though destination one should be opened instead, obtained in result of executing items 1 to 7.\r
318 4. Something more is not OK? May be, you missed something reading instructions, sorry.\r
319 5. Yes, certainly, any thing can have place. Try to do an experiment in ideal circumstances: install Delpi again (or on another PC), and try to do all exactly as it is said in instructions, step by step. Sure, all must be OK.\r
320 6. Just in case: system.dcu replacement package files must not be installed together with other files of KOL and MCK. Place it in another directory, please.\r
324 -----------------------------------------------------------------\r
325 http://bonanzas.rinet.ru OR http://xcl.cjb.net\r
326 bonanzas@online.sinor.ru OR bonanzas@xcl.cjb.net\r
328 -----------------------------------------------------------------\r
329 (C) 2000-2002, Vladimir Kladov. All rights reserved.