While programs have one location where you define a uses clause (directly below the program ProgramIdentifier; line), units have two possible locations. Units can be used directly after the interface keyword or directly after the implementation keyword. The difference is very important. In most cases one will use units from the interface section. If this is done, there is no need to reference the unit again in the implementation section. However, there are situations (which we will discuss later) in which one has to reference the unit in the implementation section only.

To practice coding units, open the project in Unit1/UnitPractice. Although we can add a unit by going to the file menu and choosing New Unit, this is NOT recommended when using Lazarus because it can at times be buggy. Instead, simply create a new text file by going to File -> New and then selecting Text from window that pops up (this also works for for Delphi). Enter the following code into the blank text file:
unit MathConsts;
interface

implementation

end.
Notice that syntax highlighting is not active yet because the editor thinks this is a plain text file. Now click Save and save this unit with the filename MathConsts.pas in the Unit1/UnitPractice directory (In Object Pascal the filename of the unit and the UnitIdentifier must be the same). Ignore any warnings about file naming (i.e., select keep same name if you are prompted to change it). Now declare a constant named PICONST in the interface section that represents the value of pi (approximately 3.1415926535). Your unit should look like the following (it is often common to fully capitalize the names of constants):
unit MathConsts;
interface

const
  PICONST = 3.1415926535;

implementation

end.
Now create and save another unit called MathRoutines. Declare a procedure in the interface section called CircleArea and then implement it in the implementation section (as you might guess, it should take in a real such as Radius and return the area of a circle which is ). The MathRoutines unit should now look like this:
unit MathRoutines;
interface

function CircleArea(Radius : Double) : Double;

implementation

function CircleArea(Radius : Double) : Double;
begin
  Result := PICONST*Radius*Radius;
end;
end.
Now go back to the program called UnitPractice, type uses MathRoutines under the program line, and compile (Ctrl+F9). The program throws an error and goes to the line containing PICONST because it does not know the identifier PICONST. We can remedy this by using MathConsts inside of MathRoutines. Since PICONST is not used until the implementation section, we will place the uses clause there but we could have just as easily placed it below interface:
unit MathRoutines;
interface

function CircleArea(Radius : Double) : Double;

implementation
uses MathConsts;

function CircleArea(Radius : Double) : Double;
begin
  Result := PICONST*Radius*Radius;
end;
end.
Now write a program that asks the user for a radius and returns the area of a circle using the functions from these units and compile it (Ctrl+F9).
program Units;
uses MathRoutines;
VAR
  Radius : Real;
begin
  Write('Enter a radius: ');
  Readln(Radius);
  Writeln('The area of the circle is ',CircleArea(Radius));
  Readln;
end.