Next: , Previous: References, Up: Documenting Your Code


3.10 Mixing Code and Documentation

Thanks to the Txt2FPDoc preprocessor, we can mix source code and documentation. This is achieved with the include directive.

     Example: documentation.txt  
      1  Package: MyPkg
      2
      3  $include 'myunit.pas'
      4
      5  End Package: MyPkg

The $include directive (line 3) imports myunit.pas. As it is a pascal file, only documentation comments are imported (see $include).

And here is the file myunit.pas with documentation located in comments.

     Example: myunit.pas  
      1  {**
      2    Unit: MyUnit
      3
      4    MyUnit contains some essential routines.
      5
      6    This unit is the result of many years of
      7    hard work.
      8
      9    I  hope they will help to save mankind. }
     10  unit MyUnit;
     11
     12  interface
     13
     14  {**
     15  Function: Max -- Return largest of two values.
     16
     17    Max returns the maximum of A and B.
     18
     19    Parameters:
     20      - A -- first value
     21      - B -- second value }
     22  function Max(A, B: Integer) : Integer;
     23
     24  {**
     25    Function: Min -- Return smallest of two values.
     26
     27    Min returns the minimum of A and B.
     28
     29    Parameters:
     30      - A -- first value
     31      - B -- second value }
     32  function Min(A, B: Integer) : Integer;
     33
     34  implementation
     35
     36  end. {** End Unit: MyUnit}