From Clomosy Docs

Procedures are subprograms that, instead of returning a single value, allow to obtain a group of results.

A procedure is defined using the void keyword. The general format of a procedure definition is as follows.

void name(argument(s): type1, argument(s): type 2, ... );
   < local declarations >
{
   < procedure body >
}


Here are all the parts of a procedure:

  • Arguments − The argument(s) establish the linkage between the calling program and the procedure identifiers and also called the formal parameters. Rules for arguments in procedures are same as that for the functions.
  • Local declarations − Local declarations refer to the declarations for labels, constants, variables, functions and procedures, which are applicable to the body of the procedure only.
  • Procedure Body − The procedure body contains a collection of statements that define what the procedure does. It should always be enclosed between the reserved words start ( { ) and end ( } ). It is the part of a procedure where all computations are done.

Procedure Declarations

A procedure declaration tells the compiler about a procedure name and how to call the procedure. The actual body of the procedure can be defined separately.

A procedure declaration has the following syntax:

Please note that the name of the procedure is not associated with any type. For the above defined procedure clMin(), following is the declaration:


Calling a Procedure

While creating a procedure, you give a definition of what the procedure has to do. To use the procedure, you will have to call that procedure to perform the defined task. When a program calls a procedure, program control is transferred to the called procedure. A called procedure performs the defined task, and when its last end statement is reached, it returns the control back to the calling program.

To call a procedure, you simply need to pass the required parameters along with the procedure name as shown below:

Example

var
  mValue : Integer;
void calMin(x, y, z: integer; var m: integer);
{
   if (x < y)
      m = x
   else
      m = y;
   
   if (z < m)
      m = z;
}

{
  mValue = 5;
  calMin(2,3,4,mValue);
  ShowMessage('Minimum: '+ IntToStr(mValue));
}

When the above code is compiled and executed, it produces the following result: