Difference between revisions of "Function"

From Lazarus wiki
Jump to navigationJump to search
Line 9: Line 9:
  
 
A function which is part of an object is called a [[Property|property]] and can be assigned/return a value (if you can't assign a value, it would be a [[Method|method]])
 
A function which is part of an object is called a [[Property|property]] and can be assigned/return a value (if you can't assign a value, it would be a [[Method|method]])
 +
 +
== Function  parameters ==
 +
 +
* Call by value
 +
* [[Variable parameter]] (call by reference)
 +
* Out parameter
 +
* Const parameter
 +
* [[Default parameter]]
 +
* Open array parameters
 +
* Array of const
  
 
== Examples ==
 
== Examples ==

Revision as of 19:48, 19 February 2016

Deutsch (de) English (en) español (es) suomi (fi) français (fr) русский (ru)

Overview

A function is a declaration of a routine which may be invoked

  • from within the unit that declares it
  • from outside the unit if the function is public,
  • or from within a program

The routine returns a value as part of its definition. A routine that does not return a value as part of its definition is a procedure.

A function which is part of an object is called a property and can be assigned/return a value (if you can't assign a value, it would be a method)

Function parameters

Examples

Addition of two integers example:

 function add(c1, c2 : integer) : integer;
 begin
 add := c1 + c2; //or use result := in Object Pascal/Delphi mode
 end;

 var 
   total: integer;

 begin
   total := add(4, 5);
   writeln (total); // result is 9
 end.