[comp.lang.pascal] problems with units

CDCKAB%EMUVM1.BITNET@cunyvm.cuny.edu ( Karl Brendel) (12/27/90)

Date:         Mon, 24 Dec 90 19:24:47 GMT
Reply-To:     Pascal Language Discussion List
 <PASCAL-L%TREARN.BITNET@uga.cc.uga.edu>
Sender:       Pascal Language Discussion List
 <PASCAL-L%TREARN.BITNET@uga.cc.uga.edu>
From:         S94%TRANAVM1.BITNET@uga.cc.uga.edu
In article <9012241543.aa15594@VIM.BRL.MIL>,
  S94%TRANAVM1.BITNET@uga.cc.uga.edu (Ozcan Akyazi) wrote:

>I've written a pascal program to copy the graphic screen to the
>printer. It worked as i want it to .But when i compiled it as a
>unit,  i encountered problems.I wonder if  i made a fatal logical
>error by writting   something like this ..  (I'm using turbo pascal
>5.5)
>
>Unit Scr2prt ;
>Uses printer , graph ;
>------------
>----------------
>end ;
>
>Program Main ;
>uses scr2prt , graph  , printer ;
>------------------
>------------
>end.
>
>Is there  anything wrong with this program body? Can i  declare
><GRAPH> and <PRINTER> with uses clause both in the unit as well as
>in the main program.Could you  inform if there is an easier way to
>accomplish the same result by using machine codes.

Putting both graph and printer in the USES statement in both the
unit and main program is not a problem. Neither is it a problem to
change the order in which they appear in the two statements.

You don't indicate what problems you encountered. The look of your
example suggests that you have the unit and the main program both in
the same file. Is this the case?

The unit must be in a separate main file from a program (or other
unit) which uses it. It is organized and compiled just like a main
program, except that it must have a UNIT statement instead of the
(optional) PROGRAM statement and it must have INTERFACE and
IMPLEMENTATION sections. Just like a program, it must end with
"end.", not "end;". If there is initialization code for the unit, it
must be placed between a "begin" and the final "end.". However, even
without the initialization code, the "end." is required.

Reworking your example would give this in the file SCR2PRT.PAS:

Unit Scr2prt ;
Uses printer , graph ;
interface
  procedure SomeRoutine;
------------
----------------
implementation
  procedure SomeRoutine;
  begin ..... end;

begin {optional initialization code}

end.

and in the file MAIN.PAS:

Program Main ;
uses scr2prt , graph  , printer ;
------------------
------------
end.

Please excuse me if this tells you nothing new or helpful. If that
is the case, please specify what problems you encountered.

+--------------------------------------------------------------------+
| Karl Brendel                           Centers for Disease Control |
| Internet: CDCKAB@EMUVM1.BITNET         Epidemiology Program Office |
| Bitnet: CDCKAB@EMUVM1                  Atlanta, GA, USA            |
|                        Home of Epi Info 5.0                        |
+--------------------------------------------------------------------+

37KGLLQ@CMUVM.BITNET (Tony Papadimitriou) (12/27/90)

Hi,

>Reworking your example would give this in the file SCR2PRT.PAS:
>
>Unit Scr2prt ;
>Uses printer , graph ;
>interface
>  procedure SomeRoutine;

You should place the uses clause either after the INTERFACE or IMPLEMENATION
declaration, not after the UNIT.