Object Pascal allows parameters of the same type to be listed together, separated by commas, and followed with a single data type (more params of different data types can follow, after a semi-colon).
Delphi also supports default parameters (a form of overloading).
By Reference or Value (and by constant): The default for parameters is by value. For by reference, add var in front of the parameter. Object Pascal also offers constant parameters where you add const in front of the parameter. A constant parameter is like a local constant or read-only parameter the compiler can optimize. You cannot assign a value to a constant parameter, nor can you pass one as a var parameter to another routine. (But when you pass an object reference as a constant parameter, you can still modify the object's properties.)
function Add(a, b: integer) : integer; begin Result := a + b;end; procedure ReplaceTime(var pDT: TDateTime; const pNewDT: TDateTime);beginend;
By Reference or ValueFor parameters, you can optionally specify ByVal or ByRef. ByRef is the default if you don't specify.
Function SomeRoutine(ByRef pPerson, ByVal pName, Age)
In C# the data type of each parameter must be specified, even if adjacent parameters are of the same type. To pass a parameter by reference, use the ref or out keyword.
integer Add(int a, int b)
By Reference or Value (and by constant)The default for parameters is by value. For by reference, add var in front of the parameter. ObjectPAL also offers constant parameters where you add const in front of the parameter. A constant parameter is like a read-only parameter the compiler can optimize. You cannot assign a value to a constant parameter.
method cmCode(s String) ;...s is by value.endMethod
method pushButton(var eventInfo Event)
;...eventInfo is by reference.endMethod
method cmCode(Const s String)
;...s is a constant read-only parameter.endMethod proc cpNever() String return "Never duplicate a line of code!"endProc
DefiningPrism allows parameters of the same type to be listed together, separated by commas, and followed with a single data type (more params of different data types can follow, after a semi-colon).
By Reference or Value (and by constant and out)The default for parameters is by value. For by reference, add var in front of the parameter. Prism also offers constant parameters where you add const in front of the parameter. A constant parameter is like a local constant or read-only parameter the compiler can optimize. You cannot assign a value to a constant parameter, nor can you pass one as a var parameter to another routine. (But when you pass an object reference as a constant parameter, you can still modify the object's properties.) Finally, Prism offers an out parameter type which is like a var parameter except it does not have to be initialized prior.
By Reference or ValueFor parameters, you can optionally specify ByVal or ByRef. ByVal is the default if you don't specify which is changed from VB Classic (in VB Classic, ByRef was the default).
Private Function Add(ByRef a As Integer, _ ByRef b As Integer) As Integer Add = a + bEnd Function