Printing from FileFlex Databases

FileFlex users often want to print data from their databases. Yet FileFlex itself does not support printing. There are, however, a number of printing options available. First, of course, you could use FoxPro or Access to print a report. You could also use PrintOMatic, from G/Matter. Finally, you could use a new product, called mPrint, from the strangely capitalized "the MEDIA shoppe". This article was written by Cary Baer, of "the MEDIA shoppe" and discusses interfacing FileFlex to mPrint. Since the article wasn't written by Component, some of the writing style will differ from the rest of the manual. Also, if you need mPrint technical support, even as it pertains to FileFlex, you'll need to contact Cary. Have fun!

Often it becomes necessary to print a report based on the contents of a database, or the contents of a user generated query from a database. Typically, this is one of the last tasks in a project to be accomplished, and there is never enough time to accomplish it. So the result is a simple, basic report.

There is, however, a tool on the market that will allow you, with very limited work, to produce beautiful reports of your data with very little work. In fact, mPrint for Director and Authorware, by "the MEDIA shoppe" will allow you to generate beautiful reports without writing any code. mPrint can be downloaded from "the MEDIA shoppe" web site at If you have ever tried to create a report in Director, you've probably spent weeks trying to get it right, and wasted rheams of paper trying to come up with a report that looks "just ok". With mPrint, your report is created visually with drag and drop, point and click, simplicity. mPrint allows you to place text, images, text files, RTF files, shapes, lines, and of course, your data generated either in your Director movie, or from a FileFlex database.

The steps to creating a report are as follows.

  1. Use the mPrint designer to design your report
  2. Save the file and use the designer to generate Director lingo.
  3. Copy the code and place it in Director cast meber script.
  4. Add into the code your local variables, or database query results.
  5. That's all

How to design a report

Open up the mPrint designer and begin a new report. You can specify some general report properties, in the Report Style dialog:

Select OK. Next you will be looking at a blank report.

The toolbar at the top provides you with easy access to all the different report components.

Report Components

An mPrint report contains the following parts:

Fixed Region
mPrint is built around the idea of regions. A region is an area that you specify somewhere on the report layout. A fixed region is an area that will always print in the same place on every page of the report.

Title Region
A title region is a special fixed region that only prints once. This is to give you the ability to create a title that will only appear on the first page. Any component placed on this region will only be seen on the first page of the report.

Repeat Region
A repeat region differs from a fixed region in that a repeat region is meant to hold variables that the Director application will specify. A repeat region is repeated as many times as it is called from the Director application. The end result is a report that shows a repetitive listing of values that are sent from Director.

RichText Region
A rich text region is a special region that shows rich text loaded from a file. Or it can be used to enter multiple lines of text directly. The runtime location of the rich text file can be chosen as the default location. Also, a rich text file can be specified at runtime from Director, the same way a variable is set from Director. The rich text will appear on the report in the exact location and size specified at design time.

A shape region is a special kind of fixed region that can appear in the shape of a rectangle, ellipse, rounded rectangle, horizontal line, or vertical line. You can also specify fill patterns, border patterns, border thickness, fill color, and border color.

The image region is a special region that shows a bitmap image loaded from a file. The runtime location of the image file can be chosen as the default location that was specified in the Report Style, or an another location can be specified. Also, an image file can be specified at runtime from Authorware/Director, the same way a variable is set from Authorware/Director. The image will appear on the report in the exact location and size specified at design time.

The text component will place one line of text onto your report. It can be used for titles, column headings, notes, or whatever seems suitable for a single line of text. For multiple lines of text, use the RichText Region. A text style can be associated with the text to give it any look you want.

mPrint allows you to place variables on the report. A variable is like text accept that its value is decided when Authorware/Director is running, rather than at the time you are designing the report. This is how values from your database finds its way onto the report.

Adding the First Component to the Report

The first item to be place on the report is always a fixed region. Select the far left icon in the toolbar or select Region>Fixed from the Add menu, then left click on the report. A fixed region will appear on the report. If you right click on the fixed region you will see a popup menu, where you can change the name of the region, and other properties of the region. Choose "Maximize Region". This will enlarge the region to fill the page.

Adding Text to the Report

Next we can add some text to the region. Using the Icon bar, place the designer in text mode, or you can select text from the Add menu. Position the cursor over the region and left click to place text on the region.

Add three pieces of text, one underneath the other. If you need to move the text, place the designer in Move mode by either going to the Edit menu and selecting move, or selecting move from the toolbar. If you move the text to a place you don't want, or can't find where you moved it to, just undo the move by going to the Edit menu and selecting undo.

To change the content of the text, right click on the text and choose "Edit Text", Change the first items to say "Name:", the second to "City:", and the third to "State:".

Adding Variables to the Report

In the same way that you added text, let's add three string variables. Select Variables from the Add menu and choose "String".

Place three variables, each to the right of the three pieces of text that we just placed. Right click on the first variable and select "Edit Variable Name". Rename the variable to "vName". Repeat for the other two variables. Rename them to "vCity", and "vState". You can name the variables anything that you want; the "v" is just so one can easily see that they are variables and not text.

Creating a Text Style

Next we will define a text style. Rather than having to specify the attributes of every text or variable on your report individually, mPrint allows you to create a text style which defines the font, size, attributes (bold, italic, underline, strikethrough) and color. You save the style under a style name, and then that style is available to all text and variables in your report. All you have to do is assign the desired style to the text or variable. Styles can either be local to your report, or global and available to all reports. You can have up to 10 styles in a single report.

Go to the "Style" menu, and choose, "Add Text Style". A dialog box will display that will allow you to select a name. Press the "Change Font" button to bring up a standard windows font dialog box and create your style.

Assigning a Style

Now right click on one of the text items and select "Select Style" and choose the new style that you just created. Right click on the other text and repeat the same steps. If you would like to assign this style or a different style to the variables, you can right click and select "Select Main Style" from the popup menu.

Next, let's save the file.

Go to File>Save and save the file to your working folder. Name it "simple1.mpf"

mPrint will automatically generate all the code that you need. You simply copy the code and paste it into your cast member script. It is not necessary to clutter up your application with all the details of the report. (text, lines, text styles etc). The code serves two purposes:

  1. To allow you to print or preview the report at the correct time in the Director movie.
  2. To give you a hook to send in your data to the report.

Go to the Code menu and select Generate>Director Lingo. A code window should display that contains all the code necessary to print your report. Right click on the code window and select "Select All". Then right click again and select "Copy".

Open up Director and Insert a Push Button onto the stage. Inside the cast member script, paste the code from mPrint.

The code should look something like:

set object = New(xtra "tMsMPrint")
tMsCreateReport(object, the pathname&"simple1.mpf")

Line 1 -- used to create an mPrint xtra object. Line 2 -- used to register mPrint -- registered users place a registration code in place of "mp-xxxxxxxxxx" so that "UNREGISTERED" banner does not appear on the printout. Line 3 -- Creates a report based on the design saved in simple1.mpf. Lines 4,5,6 -- used to start a region that contains variables that must be sent data from Director. Line 7 -- ends the current region Line 8 -- prints the report. This line can be changed to tMsPreviewReport(object) if you want to preview the report before printing. Or this line can be changed to tMsPrintWithDialog(object) if you want the standard windows print dialog box to be shown before printing. Line 9 -- frees memory when the report is complete.

Lines 4,5,6 need to be modified to include either local variables or data from your database. In this example, modify the script to look something like:

set myName = "John Smith"
 set myCity = "San Francisco"
 set myState = "California"
set object = New(xtra "tMsMPrint")
tMsCreateReport(object, the pathname&"simple1.mpf")

Notice that lines 4,5,6 now have the names of variables in place of "--value--"

Running the Example

Save the Director application in the same folder that you saved the mpf file in. Name it "simple1.dir" Now run the example. When you press the push button the report will print. This may take a few seconds while the report generates itself. If you changed line 8 of your code to tMsPreviewReport, you should see the previewer come up with your report.

Hooking FileFlex to mPrint

Note: You will need to download the File Flex Restaurant Guide example to follow along with the rest of this chapter.

Hooking a FileFlex database to mPrint only requires one change to the code you have already seen. First, you use FileFlex to extract the data. Then you use mPrint to assign the data to a printed report. Here's an example:

on mouseUp 
 put DBGetFieldByName("RESTAURANT") into CurrentRest
 put DBGetFieldByName("CITY") into CurrentCity
 put DBGetFieldByName("ADDRESS") into CurrentAddress
 put DBGetFieldByName("CUISINE") into CurrentCuisine
 put DBGetFieldByName("STATE") into CurrentState
 put DBGetFieldByName("ZIP") into CurrentZipCode
 put DBGetFieldByName("AREACODE") into CurrentAreaCode
 put DBGetFieldByName("PHONE") into CurrentPhone
 put DBGetFieldByName("SPECIALITY") into CurrentSpeciality
 put DBGetFieldByName("COST") into CurrentPrice
 put DBGetFieldByName("MAP") into CurrentMap
 set object = New(xtra "tMsMPrint")
 tMsCreateReport(object, the pathname&"rest.mpf")

Notice the only difference between this example and the simple1 example is that the local variables are getting their values from the database, instead of directly. This is an easy way that you can print the results of a query or a user selected record in a database.

More on mPrint

So far the examples have been very simplistic. Before going any further in the Restaurant Guide example, you may want to look at some more detailed mPrint examples and information that can be found bundled with mPrint, and on the mPrint web page.

Pay close attention to dynamically loaded images, dynamically loaded rich text regions, and repeat regions. There is a vital article on repeat regions that will give you the knowledge to understand where the true power of mPrint lies.

Printing Multiple Records

What if you need to print more than one record, like a table of data based on a query? mPrint handles this by using the RepeatRegion. A repeat region will repeat on the printed page, every time it is called, using the tMsBeginRegion function. the Restaurant Guide example, look at the script for the push button named "Print All", located in frame 20. As you can see, this is more complex than the first example. Of course, mPrint still generates most of this code for you. The generated code looks like:

set object = New(xtra "tMsMPrint")
tMsCreateReport(object, the pathname&"rest2.mpf")
   repeat with i=1 to --loop count--
   end Repeat

The changes you need to make are:

The final code looks like:

on mouseUp 
 global QueryType
 set object = New(xtra "tMsMPrint")
 tMsCreateReport(object, the pathname&"rest2.mpf")

put DBQuery(field "Query Expression") into dbResult checkFail dbResult, "Error performing find-all query." repeat while dbResult <> 3 put DBGetFieldByName("RESTAURANT") into CurrentRest put DBGetFieldByName("CITY") into CurrentCity put DBGetFieldByName("ADDRESS") into CurrentAddress put DBGetFieldByName("STATE") into CurrentState put DBGetFieldByName("AREACODE") into CurrentAreaCode put DBGetFieldByName("PHONE") into CurrentPhone tMsBeginRegion(object,"Region2") tMsSetVariable(object,"vAddress",CurrentAddress) tMsSetVariable(object,"vCity",CurrentCity) tMsSetVariable(object,"vState",CurrentState) tMsSetVariable(object,"vName",CurrentRest) tMsSetVariable(object,"vAC",CurrentAreaCode) tMsSetVariable(object,"vPhone",CurrentPhone) tMsEndRegion(object) put DBSkip(1) into dbResult end repeat tMsEndRegion(object) tMsPreviewReport(object) tMsFreeReport(object) end

Run the example again, specify search criteria to come up with a list of restaurants. Then press "Print All". You should print a tabular list of restaurants.


If after trying these examples, you still have questions regarding mPrint and printing FileFlex databases, please contact "the MEDIA shoppe" at

Discuss this chapter on the FileFlex Boards.

Copyright © 1992-1998 by David Gewirtz, under license to Component Enterprises, Inc.

Casa de Bender