Board index » delphi » Units using units

Units using units

   You must include "Uses" statement(s) in all Unit or program sources
which reference data, procedures, or functions in this Units.  There is
no "indirect referencing" of the type you're attempting.  (Besides,
except for the CRT Unit, unreferenced Unit information is discarded
through TP's Smart Linking.)
Quote
> I have a following piece of code that does not work:
> {begin unit mazework}
> unit mazework;
> interface
> uses graph,crt;
> .....blah blah blah....
> implementation
>   ...blah blah blah...
> end. {end unit mazework}

> {begin main program}
> program my_program;
> uses mazework;
> begin
> {calls to procedures and functions in units graph and crt}
> end. {end main program}

> This piece of code does not work because my_program does not see procedures
> in graph and crt, despite the fact that they are used in the interface
> section of the unit mazework.  I would like to know if there is some way
> around that, or do I *have* to add the line "uses graph,crt;"  to the text
> of the main program.

 

Re:Units using units


Quote
> I have a following piece of code that does not work:
> {begin unit mazework}
> unit mazework;
> interface
> uses graph,crt;
> .....blah blah blah....
> implementation
>   ...blah blah blah...
> end. {end unit mazework}
> {begin main program}
> program my_program;
> uses mazework;
> begin
> {calls to procedures and functions in units graph and crt}
> end. {end main program}
> This piece of code does not work because my_program does not see procedures
> in graph and crt, despite the fact that they are used in the interface
> section of the unit mazework.  I would like to know if there is some way
> around that, or do I *have* to add the line "uses graph,crt;"  to the text
> of the main program.

In theory you _may_ access units used in the interface parts of other
units, in this case by the "qualified" syntax

        uses mazework; { uses CRT in its interface part }
        begin
          crt.clrscr
        end.

but this practice is not recommended because the (indirect)  use of
CRT is not made explicit and your code may get invalid if you change
the unit 'mazework'. Explicitly using an unit in every program/unit
where you access it doesn't add one byte of code to your EXE.

Regards
Horst

Other Threads