Building Models

In ModelMaker you work on a single model at a time. Opening a different model will close the model you are currently working on. There are a total of nine views on the model, each giving you access to different aspects of it. Some of these views are interlinked; selecting something in one view will show detailed information in another view. For example selecting a class in the Class Tree View will show the class parts for that class in the Class Parts View. All views are described in the Modeling Environment .

You start designing in ModelMaker with either a new empty model or by opening a template model and then saving it as your new model. We have include a template named "template.mmm" that you can use as the starting point for your own models.

Then you start adding classes by inserting them into the Diagrams View or into the Class Tree View. You can then add or restructure inheritance relations between classes visually in the Diagrams View or by drag and drop in the Class Tree View. You can add documentation to a class by clicking the edit documentation button in the Class Tree View. The documentation that is entered is then visualized immediately in the Documentation View, which is a build-in HTML browser.

After the initial sketch of the class tree, you use the Class Parts View to override methods, add fields, properties, methods and events to a class in the Class Parts View. Then you select a method in the Class Parts View and you type in code in the Method Implementation View.

Properties can generate their own access methods including code to access the property state field. Units can be created in the model to define into what files classes are to be generated. Dragging a class onto a unit puts it into that unit.

We have created three demonstrations to illustrate the building of a model and its subsequent use in Delphi.

Hello World

Purpose

This example will show you what you have to do to get a component from ModelMaker into the component library.

Although the steps for creating the THelloLabel component are described in the following section, you might want to read it and then just look at the end result found in the zip file "hello.zip".

Modeling the Component

Open the template model "template.mmm" and save it as "hello.mmm". You now have a starting point for your model. Now open the Class Tree View and select the TComponent class. Then press the Add class button and fill in the name TLabel in the following dialog. After closing the dialog by clicking OK, the TLabel class is created as a direct descendant of TComponent. In the real visual component library TLabel is not a direct descendant of TComponent, but the association we have here is good enough. Now select the TLabel class and create a descendant THelloLabel the same way the TLabel class was created.

Selecting THelloLabel and open the Class Parts View. This view will be empty, because we did not add any class parts to the class. Now in the Class Parts View click the Override Methods Wizard button and in the following dialog select the "Loaded" method for overriding. After clicking OK you will notice that a method Loaded appeared in the Class Parts View. Select this method and open the Method Implementation View to edit its implementation.

In the Method Implementation View you will notice that a call to the inherited method has been generated automatically. Now you will have to add a new code fragment with the Add button. You can edit the fragment in the code editor just below the list of fragments.

Now in the code editor add the following line:

Caption := 'Hello World';

Commit the changes to this fragment with the "V" button. You have succeeded when the text "modified" disappears.

Generating the Unit

Now that you have created the component, it must be placed in a unit.

Open the Units View and add a new unit by pressing the Add unit button. In the subsequent dialog type in the name of the unit i.e. "HELLO.PAS". Now drag the THelloLabel component from the Class Tree View onto the unit name, a dialog will ask you if you want to add the class to the unit. After clicking OK the class is added and the character "M" will appear in front of the unit name to indicate that it has changed and now is different from the unit on disk.

In the unit code itself add the unit StdCtrls to the uses class of the interface and remove the uses clause from the implementation. The unit MMUtils in that uses clause is not needed in this example.

We now have to add some code that will register the component with the Delphi component library. Add the following line to the interface of the unit:

procedure Register;

The implementation of this procedure that must be put in the implementation section of the unit is as follows:

procedure Register;
begin
RegisterComponents('MMDemo', [THelloLabel]);
end;

The unit is finished and can be generated to the unit file by clicking the Generate current unit button or by clicking the Enable current unit button. When you have successfully done this the "M" character has disappeared and a freshly generated unit has appeared on your disk.

Registering the component in Delphi

You add the component to the component library as you normally do with new components. When the component has been rebuild, you will see a new tab "MMDemo" that contains the component.

When you put the THelloLabel on a form and execute the project, the label will display the text "Hello World".

Tour of the Netherlands

Purpose

This example shows you all the important features of ModelMaker. You can find the complete demo project in the zip file "tour.zip". By examining the model and the generated code you will be able to figure out how model and generated code is related.

Old Friends

Purpose

The Old Friends example demonstrates how we incorporated some BP 7.0 style components we got attached to in the Delphi and ModelMaker environment. This example uses the library files "mmutils.pas", "containr.pas" and "filters.pas". The example itself is in the zip file "friends.zip".