home  |   software development  |   user experience  |   training services  |   print  |   audio  |   contact  
 
Getting Started with ModelMaker
Tutorial 6 — Delphi Integration
 
 
Tutorial 6
While some developers use ModelMaker as a complete Delphi IDE replacement, most seem to prefer to use ModelMaker and Delphi simultaneously — switching back and forth as needed. To support this, ModelMaker offers extensive Delphi integration features, which we will examine here.

Delphi Controls ModelMaker
ModelMaker installs a Delphi integration expert into the Delphi IDE, which allows you to control ModelMaker somewhat from within Delphi.
First, start Delphi if it is not running, and have a look at the ModelMaker menu in the main Delphi menu bar. Notice that the first menu item allows you to launch ModelMaker. Also notice that most of the items in the ModelMaker menu require ModelMaker to be running — if it is not, those items will be disabled.
Launch ModelMaker now, if it is not running, by selecting the first menu item.
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 first thing we'll do is to create a new project and import into it some existing classes, all from within Delphi. Open, in Delphi, a project that you'd like to import into ModelMaker. From the ModelMaker menu, select Convert Project to Model. The ModelMaker window should come to the front, most likely asking whether to save your current model. After you answer that dialog as appropriate, ModelMaker will create a new project and import the Delphi project's units.
Some of the other menu items that operate similarly are Add to Model, which causes the active unit in Delphi to be imported into the current model in ModelMaker; Add Files to Model, which allows you to select units to be added to the current model in ModelMaker and Convert to Model, which will create a new model in ModelMaker and import the active Delphi unit into it.
Two other noteworthy menu items in the Delphi ModelMaker menu are Jump to ModelMaker and Refresh in Model. Jump to ModelMaker will bring ModelMaker to the front and attempt to find the current code block within the model. Refresh in Model will cause ModelMaker to re-import the active unit into the current model.
A note on contextual behavior: Add to Model and Refresh in Model behave differently depending on whether the current unit is or is not in the current ModelMaker model. If a unit is not in the current model, Add to Model will add the unit to the model, while Refresh in Model will do nothing (there’s nothing to refresh). If the current unit does already exist in the model, Add to Model and Refresh in Model will behave in the same manner — either one will re-import the unit into the model.

ModelMaker Controls Delphi
If you find that you like editing your code in ModelMaker, and prefer to have ModelMaker control Delphi, you have that option. Make sure that you are familiar with the process of generating code from within ModelMaker, by reading tutorial 1, then examine the Delphi portion of ModelMaker's main toolbar (see figure 19).

Figure 19 — Delphi
control buttons.
The first button, Generate, you should already be familiar with.
The second button, Generate and Perform Default Compile Action, will cause the current unit to be generated, and will request that Delphi perform one of three actions: Syntax Check, Compile or Build. This default compile action can be set on the next button's drop-down menu.

Figure 20 — Default Compile
Action drop-down menu.
The third button (its hint will vary depending on the default compile action), will cause Delphi to perform the currently selected default action. This default is set in this button's drop-down menu (see figure 20); after setting a default, that action will be taken any time this button or the previous button is clicked. Note: these Delphi actions will be enacted upon whatever the currently loaded Delphi project may be.
The fourth button, Locate in Delphi, will bring Delphi to the front and attempt to locate the current code block in the code editor. It will open the current unit in Delphi if necessary.

Two-way Integration
The most complete integration can be achieved through ModelMaker's two-way integration, although a warning must be issued here: normally ModelMaker works with a safety net of allowing you to determine when code will be generated and when it will be refreshed into the model. Even if you enable auto-generation (see tutorial 1), you still have control over when code is re-imported if it has been changed outside of ModelMaker. If you enable the two-way integration, you will lose this control and code will automatically be generated and refreshed without warning. If there are changes to the code you do not wish to overwrite without warning, you should be careful using this option.
Enabling this feature basically causes ModelMaker to generate your units any time they change in ModelMaker and to re-import them any time they change outside of ModelMaker. To use this feature, do the following:
In ModelMaker, unlock code generation. Select one or more units to auto-generate and select the Enable Auto-Generation button for each.
Select Environment Options from the Options menu in ModelMaker. In the General tab, under Code Generation and Import, check the Auto Refresh from IDE and Refresh Keeps Units Enabled check boxes.
In Delphi, select Integration Options from the ModelMaker menu. In that dialog, select Enable Auto Refresh.
Open one of your auto-generated units in Delphi by clicking ModelMaker's Locate in Delphi button. If you want, arrange your ModelMaker and Delphi code editor windows so that you can see both at the same time. Now go back to ModelMaker and change something in that unit, then save the model. You should see the unit update in Delphi automatically. Now change something in the unit in the Delphi code editor, then save the unit. The unit will be refreshed in ModelMaker. Viola! Two-way code editing integration.
Another warning: if your code comment importing options are not correctly set up, you may see "comment creep" or worse, you might see comments deleted without warning. Be very careful using this two-way feature until you understand how to set up code comment importing options. For more information on that, see the next tutorial.

Return to the Introduction.
Go back to the previous tutorial.
Go on to the next tutorial.