# Routine Snippets

A routine snippet, defines exactly one Pascal procedure or function. Methods are not permitted (see the class & advanced record kind for how to deal with methods).

Each routine snippet begins with either the function or procedure keyword followed by a valid Pascal routine prototype (see below). No source code or comments may precede the function or procedure keywords. The following directives may be included in the prototype:

- register
- pascal
- cdecl
- stdcall
- safecall
- overload

After the routine prototype there must be at least one space or a new line before the routine's implementation. Private functions, procedures, type definitions, variables and constants are permitted.

A routine must be fully implemented in Pascal – it can't be simply a DLL import. Therefore the external and varargs directives are not supported.

Here's an example of a valid routine snippet:

    function MyFunc(const Param1, Param2: string): string; stdcall;
    begin
      Result := Param1 + ' - ' + Param2;
    end;

Routine snippets may refer to other routines, simple type definitions, class & advanced record definitions or constants, providing they are defined in Delphi units or elsewhere in the database. The snippet's units and dependency references should indicate where to find referenced types, constants and routines. Routine snippets may not reference freeform or unit snippets.

It is important that the routine prototype is recognisable by CodeSnip because it must be able to extract the prototype for inclusion in a generated unit's interface section, amongst other things.

## Overloading

You may use overloaded routines by creating a separate routine snippet for each overloaded version of the routine. The overload directive must be used for each snippet.

While the name of the routines in source code must obviously be the same, each snippet must be given a unique name for use by the database. For example if there are two overloaded routines named `MyFunc` you could use MyFunc_A and MyFunc_B as the snippet's name in the database. The main DelphiDabbler Snippets Database has plenty of examples.