Value parameter: the value of the real parameter is assigned to the corresponding parameter. Changes in the shape parameter do not affect the real parameter.
Unit first; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) btn1: tbutton; edt1: tedit; edt2: tedit; Procedure btn1click (Sender: tobject); Private function formalparameter (X, Y: integer): integer; {private Declarations} public {public declarations} end; var form1: tform1; implementation {$ R *. DFM} procedure tform1.btn1click (Sender: tobject); var X, Y: integer; R: integer; begin X: = 1; Y: = 100; R: = formalparameter (X, y); edt1.text: = 'X = '+ inttostr (x); edt2.text: = 'y =' + inttostr (y); MessageBox (0, pchar (inttostr (R), 'r value: ', mb_ OK); end; function tform1.formalparameter (X, Y: integer): integer; begin X: = x + 1; Y: = Y + 2; Result: = x + y; end.
Output: x = 1, y = 100, r = 104
Variable Parameter: The Variable Parameter passes a reference pointing to the parameter, that is, the pointer. Changing the parameters passed by reference will affect the actual parameters.
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) btn1: tbutton; edt1: tedit; edt2: tedit; Procedure btn1click (Sender: tobject); Procedure variableparameter (var x, Y: integer); Private {private Declarations} public {public declarations} end; var form1: tform1; implementation {$ R *. DFM} procedure tform1.btn1click (Sender: tobject); var X, Y: integer; begin X: = 100; Y: = 100; variableparameter (x, y); edt1.text: = 'x value: '+ inttostr (x); edt2.text: = 'y value:' + inttostr (y); end; Procedure tform1.variableparameter (var x, Y: integer); begin X: = x + 1; Y: = Y + 1; end.
Output: x = 101, y = 101
Constant parameters: parameters passed to a function or process cannot be changed in a function or process,
Function myfunction (const X, Y: integer): integer; begin // X: = x + 1; error Syntax: The parameter value cannot be changed // y: = Y + 1; result: = x * Y; end;
4. array parameters: An array can be used as a function or process parameter, but the declaration of an array parameter cannot contain the declaration of the array index type.
Procedure sort (A: array [1 .. 10] of integer); // incorrect type tdigits = array [1 .. 10] of integer; Procedure sort (A: tdigits); // you can use dynamic arrays as parameters for functions and procedures. Example: Procedure clear (var a: array of real); var I: integer; begin for I: = 0 to high (a) Do A [I]: = 0; end;