Difference between revisions of "Procedure"

From Free Pascal wiki
m (Fixed procedure declaration link.)
m
Line 8: Line 8:
 
[[Variable parameter]]s example:
 
[[Variable parameter]]s example:
  
 
+
<syntaxhighlight>
 
  procedure swap(var c1,c2:char);
 
  procedure swap(var c1,c2:char);
 
  var c:char;  
 
  var c:char;  
Line 25: Line 25:
 
  end;
 
  end;
  
 
+
</syntaxhighlight>
  
 
= Read more =
 
= Read more =
  
 
* [http://www.freepascal.org/docs-html/ref/refse74.html#x149-15900014.1 Procedure declaration]
 
* [http://www.freepascal.org/docs-html/ref/refse74.html#x149-15900014.1 Procedure declaration]

Revision as of 14:53, 28 September 2012

Deutsch (de) English (en) suomi (fi) français (fr) italiano (it) русский (ru)

A procedure is a declaration of a routine which may be invoked from within the unit that declares it, from outside the unit if the procedure is public (declared in interface section), or from within a program, and the routine does not return a value as part of its definition. A procedure that does return a value as part of its definition is called function. A procedure that is part of an object is called a method. A function that is part of an object is also a method if it cannot be assigned a value from outside of the function, and is a property if it can be assigned a value from outside of the function.

You can also use procedure as type definition for your variables,which by it you can make your variables being treated as procedures.You can also use function for functions and procedure/function(..) of object for methods.


Variable parameters example:

 procedure swap(var c1,c2:char);
 var c:char; 
 begin
   c:=c1;
   c1:=c2;
   c2:=c;
 end;

 var s:string;

 begin
   s:='pit'; 
   swap(s[1],s[3]);
   writeln (s); // result is 'tip'
 end;

Read more