LAZARUS


  PROCEDURES AND FUNCTIONS

  procedure procedure_name (parametrs);
  var ....;
   begin
  ...... ;
  end;

The variables declared under 'var' are local variables and are only available in this procedure. This declaration may not be at all, e.g. when using only global variables (not recommended).
Example:
procedure for drawing a circle by specifying the coordinates of the centre, the radius and the size of the blue component (0  255) as the fill.

 procedure TForm1.circle(a, b, r, kolor: integer);
 begin
  canvas.brush.color := RGB(0, 0, kolor);
  canvas.ellipse(a+r, b+r, a-r, b-r);
 end;


  FUNCTIONS

  function function_name (parametrs): result_type;
 var ....;
 begin
  ......;
  result:= ………… ;
 end;

Variables declared in "var" are local variables and available only in this function. This declaration may not be at all, e.g. when using only global variables. Instead of deriving the result of a function through "result" it is possible to substitute the name of the function, which then takes over the properties of the variable.

 function function_name (parametrs): result_type;
 var ....;
  begin
  ......;
  function_name:= ………… ; {result}
 end;


Example:  the function determines the colour in the RGB convention using the TColor type.

 function TForm1.RGB(r,g,b: byte):TColor;
 begin
  result:=(b shl 16) or (g shl 8) or r;
 end;

The procedures and functions described must have their own headings in the public section. The names must then not contain an assignment to a form.

 public
  function RGB(r,g,b: byte):TColor;
  procedure circle(a,b,r,kolor: integer);


  CALL

Procedures and functions are called by entering their names with current parameters.
Example: the use of the „circle” procedure and the „RGB” function