Previous: Rationale
Up: Creating a Monoprogram Dialog
with Turbo Pascal
Next: Converting Attract Mode into Main Program
Previous Page: Rationale
Next Page: Units Belonging to Modules
Most modules convert to units relatively easily:
- Declare the following compilation flag at the head of the
main file: {$DEFINE MonoProg}. Each of the following
structures to be inserted into the module should have as its
alternative its original form from the main program, controlled
by checking this compilation flag.
- prepend to the module's main file a UNIT interface section.
The unit name can be the same as the program name. It need export
only the routine that will run the module. The routine should take no
parameters. Note that all
the unit's global declarations should be in the IMPLEMENTATION
section. The MonoProg flag will control whether this interface
or the old program heading is compiled.
One scheme is to name each such routine Activity n,
n being the number of the module.
- turn the body of the former main program into the routine being
exported by inserting the procedure heading for the exported routine
just ahead of its BEGIN statement. Attempting to nest
the whole module's code inside this routine is unnecessary, and
can result in scoping problems for the module's USES statement,
which must be global to the IMPLEMENTATION section.
Whether this new header is compiled depends on the presence
of the MonoProg flag.
- the END. that used to end the main program now ends
the unit, so insert an END; just ahead of the END. .
Again, control its presence with the MonoProg flag.
- avoid adding a BEGIN to the END., which would
create an initialization body (even if empty) for the unit.
The reasons for avoiding unneeded initialization bodies in units
that implement modules are discussed
under overlaying.
- Place at the head of the file the compilation switches
{$F+,O+}. These make sure the unit will be compiled
to allow calls from any distance across the segments of 808*6 memory,
and can be
controlled by the overlay manager. Note that these switches need
not be conditionally compiled, since they make no difference to
compilation as an independent program.
Only compilation modules compiled with these switches can be overlaid.
Note that if the MonoProg flag is not defined (by
changing its declaration to {$UNDEF MonoProg}) this
arrangement will cause the module to continue to compile into its
own program, rather than a unit.
The Activity n routine that each module's unit now
exports will be called by the attract mode.
Previous: Rationale
Up: Creating a Monoprogram Dialog
with Turbo Pascal
Next: Converting Attract Mode into Main Program
Previous Page: Rationale
Next Page: Units Belonging to Modules