Transferring Your Procedures and Functions into a Library Unit

Copyright © by Mark Baker 1997

Copyright waiver

Return to MarkChrisSoft home page


Creating a Turbo Pascal Unit

There are 3 stages that you must go through, in order to create and use your own library unit.

What a unit looks like

You will need to create a .PAS file similar to the one below. It is similar to an ordinary Turbo Pascal program, however there are differences. Note especially the interface and implementation sections.


unit MyUnit;

interface

uses crt,...etc;

procedure StarGow(x,y: integer; s: string);                 {Procedure and function headers}
procedure StarLine(y: integer);
function   StopsToSpaces(s: string): string;
*	
*	
*	etc.

implementation

{--------------------------------------------------------------------------------------}
procedure StarGow(x,y: integer; s: string);                 {Procedure and function coding}
  begin
  gotoxy(x,y);
  clreol;
  gotoxy(x,y);
  write('*',s,'*');
  end; 
{---------------------------------------------------------------------------------------}
procedure StarLine(y: integer);
*	
*	
*	
*  ...etc.	
  end;  {End of last procedure or function}
{---------------------------------------------------------------------------------------}

end.   {End of unit}

To compile the unit

Before you compile it, you must first choose:

Compile / Destination

This will change the destination to disc (click on Compile on the menu bar to check that this has happened). If you then choose Compile / Compile, the .TPU file will be created. This is the machine code version of your library.

To use the unit

Include the unit's name in the uses line at the top of any program that wants access to your library, e.g.
uses crt, dos, MyUnit;

Return to MarkChrisSoft home page

Author: Mark Baker, e-mail mbaker@rmplc.co.uk
Last revision: 12th January 1997