Call by value :- 
Call by Value means that the calling program is passing the value of the literal, or identifier, not a reference to the sending item. The called program can change the parameter in the called program. However, because the subprogram has access only to a temporary copy of the sending item, those changes don't affect the argument in the calling program
Example
static void Classes_CallByValue(Args _args)
{
    MyClass_PassingValues    passingValues = new MyClass_PassingValues();
    Counter                  counter       = 100;
;
    info(strFmt("%1", counter));
    info(strFmt("%1", passingValues.callByValue(counter)));
    info(strFmt("%1", counter));
}
Call-by-reference
Call-by-reference is a way to pass an object as a parameter to a function,that any changes made by the subprogram to the variables it received are visible by the calling program.
Example
static void Classes_CallByReference(Args _args)
{
    CustTable               custTable;
    TmpAccountSum           tmpAccountSum;
    MyClass_PassingValues   passingValues = new MyClass_PassingValues();
    Counter                 counter;
;
    while select custTable
    {
        counter++;
        if (counter > 5)
            break;
        tmpAccountSum.accountNum = custTable.accountNum;
        tmpAccountSum.insert();
    }
    select tmpAccountSum;
    info(tmpAccountSum.accountNum);
    passingValues.callByReference(tmpAccountSum);
    info(tmpAccountSum.accountNum);
}
 
No comments:
Post a Comment