Passing parameters by reference
Sometimes, we may want our function to modify multiple values. As we can't return more than one value from a function (unless we use an array), it can be beneficial to pass our parameters by reference to the function.
How to do it...
Let's get started by creating a new codeunit from Object Designer.
Add the following global variables:
Name
Type
SubType
Length
CustomerRec
Record
Customer
OldName
Text
50
NewName
Text
50
Then add a function called
ChangeCustomerName
.The function should take the following parameter:
Name
Type
SubType
Customer
Rec
Customer
Let's write the following code in the
ChangeCustomerName
function:Customer.Name := 'Changed Name';
Add another function called
ChangeCustomerNameRef
.The function should take the following parameter:
Name
Type
SubType
Customer
Rec
Customer
Place a check mark in the
Var
column for the parameter.Write the following code in the
ChangeCustomerNameRef
function:Customer.Name := 'Changed...