Pascal III: Regular Units

Pascal III: Regular Units

Regular Units in Pascal allow the programmer to write and compile code in
sections.  The programmer can then link the sections to form a single code
file that will run without the need to refer to a library.  The following is a
simple example of how to write a regular unit.  It is a supplement to the
information in chapter 14 of the Programmer's Manual.
 
First let's enter the unit.  This unit has one function that asks for an
integer number and returns that number doubled. Enter the editor and enter:
 
        UNIT LIB1;
 
        INTERFACE
        FUNCTION DOUBLE (NUM:INTEGER):INTEGER;
 
        IMPLEMENTATION
        FUNCTION DOUBLE;
        BEGIN
           DOUBLE := NUM + NUM;
        END;
 
        BEGIN
          WRITELN ('LIB1 INITIALIZATION');
        END.
 
Save the file as LIB1, quit the Editor and compile the unit. Now enter the
program that will use LIB1:
 
        PROGRAM TEST1;
 
        USES {$USING LIB1.CODE} LIB1;
 
        VAR INT : INTEGER;
 
        BEGIN
           READLN (INT);
           WRITELN (DOUBLE (INT));
        END.
 
Save this file as TEST1, Quit the Editor, and Compile TEST1. Now you have the
code file for the unit and the program.  The next step is to link them
together.  Enter L from command mode to get into the Linker.
 
        The Host File is TEST1
        The Lib file is LIB1
        Just press return for the next two questions
        The output file will be TEST1
 
Now TEST1 is ready to execute.  Any time you change or re-compile either TEST1
or LIB1 you will have to re-link them.