Difference between revisions of "Unit"

From Free Pascal wiki
Jump to navigationJump to search
Line 14: Line 14:
  
 
== Format ==
 
== Format ==
A unit is defined with the UNIT keyword, an optional list of any [[global]] types, constants or variables, any public or private variables, properties, methods, and any initialization code for the unit.
+
A unit is defined with the UNIT keyword, an optional list of any [[Global|global]] types, constants or variables, any public or private variables, properties, methods, and any initialization code for the unit.
  
 
{{stub}}
 
{{stub}}

Revision as of 21:25, 13 January 2012

Deutsch (de) English (en) español (es) suomi (fi) français (fr) português (pt) русский (ru)

A unit is a source code file (or the binary compiled from that file) which was written using the Pascal programming language, and that is designed to be a single module in an application or an object module.

A unit may be used where certain functionality is to be provided to an application program or to other units, and allowing code that performs that functionality to be created once and used in many places. This can reduce the possibility of error and increase the possibility of code reuse.

A unit may be used where a program author wishes to provide certain functionality for use in a Pascal program but does not wish to provide the source code that performs that functionality.

Units were also used on older versions of Pascal when it was nececessary on computers with limited resources to be able to load routines as needed rather than keeping every routine of the executable program in memory all of the time.

A unit that needs to access e.g. procedures and data types in another unit must specify those units it needs to access in a Uses statement but linking is done without the need to write a makefile as in C.

A unit may also be used to declare a series of global constants or variables for use by the entire application, without actually containing any executable code. This is similar to the COMMON keyword in the Fortran Programming Language.

Format

A unit is defined with the UNIT keyword, an optional list of any global types, constants or variables, any public or private variables, properties, methods, and any initialization code for the unit.

An editor has declared this article to be a stub, meaning that it needs more information. Can you help out and add some? If you have some useful information, you can help the Free Pascal Wiki by clicking on the edit box on the left and expanding this page.


Read more