Warning: in order to avoid overwriting some of your production code, make a copy of the unit or units you are going to import before continuing.
The fastest way to see ModelMaker in action is to import some of your existing code.
Open ModelMaker and create a new model by selecting the New button or File|New.
At this point we are going to tell ModelMaker to import a source file — it will reverse engineer the code it finds and add it to the model. Keep in mind that while ModelMaker’s parsing engine is good, it can only deal with so much obfuscated code formatting before it chokes. For most people, this is not an issue — if MM encounters problems while importing your code, it will tell you.
Figure 1 — the empty Units View.
There are multiple ways to import a file, but the quickest way is via drag & drop.
In ModelMaker, select the Units View by pressing F4 or by selecting its tab.
Find the unit you wish to import in Windows Explorer and then position ModelMaker so that you can drag the file into MM’s main window.
Drop the unit into the Units View — if you’re in a new project that is empty, the Units View should look like figure 1.
Figure 2 — Units View with imported unit.
Once you have dropped the unit, it will be reverse-engineered. The unit and any classes it contains will be added to the Unit List, which should now look something like Figure 2.
Don’t worry if your icons look a little different — I’ve got some ModelMaker extensions installed that can change the appearance of my screens.
The top-level node in the Unit View treeview represents the unit you’ve just imported. Any child nodes are the classes, interfaces or event types that reside in that unit. You can double-click these nodes to bring up their editors.
Figure 3 — the Member List.
Note that if you select a class in the Unit View, all of its members (properties, methods, etc.) will be displayed in the Member List, which looks something like figure 3.
We’ll cover the Member List in Tutorial 5; for now it’s enough to notice that your class’ members are enumerated here.
Press F3 to switch to the Classes View. You should notice here a hierarchical representation of the classes you’ve imported. Figure 4 is an example.
Figure 4 — the Classes View.
Notice that TObject, IInterface and IUnknown are always present. Note also the appearance of my TtsCustomSplitter class in Figure 4 — this is the ancestor of TtsShutter, which I’ve imported. However because I did not (yet) import the unit containing TtsCustomSplitter, this class must be represented as a “placeholder” (note the dotted lines around the class icon which denote placeholder status.) ModelMaker knows that TtsShutter descends from TtsCustomSplitter, but that’s all it knows. If I wish to be able to use ModelMaker’s features involving inheritance, I’d have to import TtsCustomSplitter’s unit.
ModelMaker is also capable of importing your in-source comments and attaching them to their associated entities, but only if the comments and/or ModelMaker are properly set up to do so. If MM’s Unit Code Editor (F7) shows a mass of unassociated code comments, fear not — we’ll cover importing comments in Tutorial 7.
This is an extremely abbreviated example of how to import existing code. You can also perform imports using one of the two import buttons on the main toolbar.
 – this button will import your code into a new model.
 – this button will import your code into the existing model.
In both cases, the buttons will give you the option of importing from a specific path or from a Source Path Alias (which we have not covered here). See Source Path Aliases in the ModelMaker help file for more information.
Obviously our ultimate goal is to create code which can be compiled in Delphi. ModelMaker uses its internal code model and applies the various formatting options you’ve selected to generate the specified units.
In its default configuration, ModelMaker will not generate source code until you tell it to. To do so now, switch to the Units View by pressing F4 or by selecting the Units tab. Assuming you have one or more units containing classes (if you don’t, go back, use your new-found skills and import some units), first, make sure that code generation is enabled by clicking the Unlock Code Generation button in the main toolbar (see sidebar), then select a unit to generate and press the Generate button (found in the Units View toolbar — see sidebar.) You should find that the specified unit has been regenerated by ModelMaker. If the unit was open in Delphi, you'll see that Delphi has already reloaded the new version of the file. This method is handy if you don't want to generate the code until you are ready.
However, if you wish, ModelMaker can be set to automatically regenerate a unit every time you make a change to that unit. This is called Auto Generation. You can enable or disable Auto Generation for each unit in your model by clicking either the Enable or Disable Auto Generation buttons in the Units View toolbar (see sidebar). Now, anytime you make a change to an Auto Generated unit, ModelMaker will regenerate the file. For that reason, care should be taken when enabling Auto Generation.
There are several other options and Delphi integration features which can effect when and how code is generated; we'll take a look at these options in Tutorial 6.
Return to the Introduction.
Go on to the next tutorial. |